-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Support overriding the types of a set of JSON files #50095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/moduleResolutionWithExtensions_jsonOverwrite.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//// [tests/cases/compiler/moduleResolutionWithExtensions_jsonOverwrite.ts] //// | ||
|
||
//// [hello.locstring.json] | ||
{ "hello": "Hello World" } | ||
|
||
//// [types.d.ts] | ||
type ResourceId = string & { __ResourceId: void }; | ||
declare module "*.locstring.json" { | ||
const value: { [key: string]: ResourceId }; | ||
export default value; | ||
} | ||
|
||
//// [a.ts] | ||
import strings from './hello.locstring.json'; | ||
|
||
strings.hello; | ||
|
||
|
||
//// [a.js] | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var hello_locstring_json_1 = __importDefault(require("./hello.locstring.json")); | ||
hello_locstring_json_1["default"].hello; |
28 changes: 28 additions & 0 deletions
28
tests/baselines/reference/moduleResolutionWithExtensions_jsonOverwrite.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
=== /hello.locstring.json === | ||
{ "hello": "Hello World" } | ||
>"hello" : Symbol("hello", Decl(hello.locstring.json, 0, 1)) | ||
|
||
=== /types.d.ts === | ||
type ResourceId = string & { __ResourceId: void }; | ||
>ResourceId : Symbol(ResourceId, Decl(types.d.ts, 0, 0)) | ||
>__ResourceId : Symbol(__ResourceId, Decl(types.d.ts, 0, 28)) | ||
|
||
declare module "*.locstring.json" { | ||
>"*.locstring.json" : Symbol("*.locstring.json", Decl(types.d.ts, 0, 50)) | ||
|
||
const value: { [key: string]: ResourceId }; | ||
>value : Symbol(value, Decl(types.d.ts, 2, 9)) | ||
>key : Symbol(key, Decl(types.d.ts, 2, 20)) | ||
>ResourceId : Symbol(ResourceId, Decl(types.d.ts, 0, 0)) | ||
|
||
export default value; | ||
>value : Symbol(value, Decl(types.d.ts, 2, 9)) | ||
} | ||
|
||
=== /a.ts === | ||
import strings from './hello.locstring.json'; | ||
>strings : Symbol(strings, Decl(a.ts, 0, 6)) | ||
|
||
strings.hello; | ||
>strings : Symbol(strings, Decl(a.ts, 0, 6)) | ||
|
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/moduleResolutionWithExtensions_jsonOverwrite.trace.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[ | ||
"======== Resolving module './hello.locstring.json' from '/a.ts'. ========", | ||
"Module resolution kind is not specified, using 'NodeJs'.", | ||
"Loading module as file / folder, candidate module location '/hello.locstring.json', target file type 'TypeScript'.", | ||
"File '/hello.locstring.json.ts' does not exist.", | ||
"File '/hello.locstring.json.tsx' does not exist.", | ||
"File '/hello.locstring.json.d.ts' does not exist.", | ||
"File name '/hello.locstring.json' has a '.json' extension - stripping it.", | ||
"File '/hello.locstring.json.d.ts' does not exist.", | ||
"Directory '/hello.locstring.json' does not exist, skipping all lookups in it.", | ||
"Loading module as file / folder, candidate module location '/hello.locstring.json', target file type 'JavaScript'.", | ||
"File '/hello.locstring.json.js' does not exist.", | ||
"File '/hello.locstring.json.jsx' does not exist.", | ||
"File name '/hello.locstring.json' has a '.json' extension - stripping it.", | ||
"File '/hello.locstring.json' exist - use it as a name resolution result.", | ||
"======== Module name './hello.locstring.json' was successfully resolved to '/hello.locstring.json'. ========" | ||
] |
31 changes: 31 additions & 0 deletions
31
tests/baselines/reference/moduleResolutionWithExtensions_jsonOverwrite.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
=== /hello.locstring.json === | ||
{ "hello": "Hello World" } | ||
>{ "hello": "Hello World" } : { hello: string; } | ||
>"hello" : string | ||
>"Hello World" : "Hello World" | ||
|
||
=== /types.d.ts === | ||
type ResourceId = string & { __ResourceId: void }; | ||
>ResourceId : string & { __ResourceId: void; } | ||
>__ResourceId : void | ||
|
||
declare module "*.locstring.json" { | ||
>"*.locstring.json" : typeof import("*.locstring.json") | ||
|
||
const value: { [key: string]: ResourceId }; | ||
>value : { [key: string]: ResourceId; } | ||
>key : string | ||
|
||
export default value; | ||
>value : { [key: string]: ResourceId; } | ||
} | ||
|
||
=== /a.ts === | ||
import strings from './hello.locstring.json'; | ||
>strings : { [key: string]: ResourceId; } | ||
|
||
strings.hello; | ||
>strings.hello : ResourceId | ||
>strings : { [key: string]: ResourceId; } | ||
>hello : ResourceId | ||
|
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/moduleResolutionWithExtensions_jsonOverwrite2.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//// [tests/cases/compiler/moduleResolutionWithExtensions_jsonOverwrite2.ts] //// | ||
|
||
//// [hello.locstring.json] | ||
{ "hello": "Hello World" } | ||
|
||
//// [hello.locstring.json.d.ts] | ||
declare const _default: { | ||
hello: number; | ||
}; | ||
export default _default; | ||
|
||
//// [types.d.ts] | ||
type ResourceId = string & { __ResourceId: void }; | ||
declare module "*.locstring.json" { | ||
const value: { [key: string]: ResourceId }; | ||
export default value; | ||
} | ||
|
||
//// [a.ts] | ||
import strings from './hello.locstring.json'; | ||
|
||
strings.hello; | ||
|
||
|
||
//// [a.js] | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var hello_locstring_json_1 = __importDefault(require("./hello.locstring.json")); | ||
hello_locstring_json_1["default"].hello; |
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/moduleResolutionWithExtensions_jsonOverwrite2.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
=== /hello.locstring.json.d.ts === | ||
declare const _default: { | ||
>_default : Symbol(_default, Decl(hello.locstring.json.d.ts, 0, 13)) | ||
|
||
hello: number; | ||
>hello : Symbol(hello, Decl(hello.locstring.json.d.ts, 0, 25)) | ||
|
||
}; | ||
export default _default; | ||
>_default : Symbol(_default, Decl(hello.locstring.json.d.ts, 0, 13)) | ||
|
||
=== /types.d.ts === | ||
type ResourceId = string & { __ResourceId: void }; | ||
>ResourceId : Symbol(ResourceId, Decl(types.d.ts, 0, 0)) | ||
>__ResourceId : Symbol(__ResourceId, Decl(types.d.ts, 0, 28)) | ||
|
||
declare module "*.locstring.json" { | ||
>"*.locstring.json" : Symbol("*.locstring.json", Decl(types.d.ts, 0, 50)) | ||
|
||
const value: { [key: string]: ResourceId }; | ||
>value : Symbol(value, Decl(types.d.ts, 2, 9)) | ||
>key : Symbol(key, Decl(types.d.ts, 2, 20)) | ||
>ResourceId : Symbol(ResourceId, Decl(types.d.ts, 0, 0)) | ||
|
||
export default value; | ||
>value : Symbol(value, Decl(types.d.ts, 2, 9)) | ||
} | ||
|
||
=== /a.ts === | ||
import strings from './hello.locstring.json'; | ||
>strings : Symbol(strings, Decl(a.ts, 0, 6)) | ||
|
||
strings.hello; | ||
>strings.hello : Symbol(hello, Decl(hello.locstring.json.d.ts, 0, 25)) | ||
>strings : Symbol(strings, Decl(a.ts, 0, 6)) | ||
>hello : Symbol(hello, Decl(hello.locstring.json.d.ts, 0, 25)) | ||
|
9 changes: 9 additions & 0 deletions
9
tests/baselines/reference/moduleResolutionWithExtensions_jsonOverwrite2.trace.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
"======== Resolving module './hello.locstring.json' from '/a.ts'. ========", | ||
"Module resolution kind is not specified, using 'NodeJs'.", | ||
"Loading module as file / folder, candidate module location '/hello.locstring.json', target file type 'TypeScript'.", | ||
"File '/hello.locstring.json.ts' does not exist.", | ||
"File '/hello.locstring.json.tsx' does not exist.", | ||
"File '/hello.locstring.json.d.ts' exist - use it as a name resolution result.", | ||
"======== Module name './hello.locstring.json' was successfully resolved to '/hello.locstring.json.d.ts'. ========" | ||
] |
36 changes: 36 additions & 0 deletions
36
tests/baselines/reference/moduleResolutionWithExtensions_jsonOverwrite2.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
=== /hello.locstring.json.d.ts === | ||
declare const _default: { | ||
>_default : { hello: number; } | ||
|
||
hello: number; | ||
>hello : number | ||
|
||
}; | ||
export default _default; | ||
>_default : { hello: number; } | ||
|
||
=== /types.d.ts === | ||
type ResourceId = string & { __ResourceId: void }; | ||
>ResourceId : string & { __ResourceId: void; } | ||
>__ResourceId : void | ||
|
||
declare module "*.locstring.json" { | ||
>"*.locstring.json" : typeof import("*.locstring.json") | ||
|
||
const value: { [key: string]: ResourceId }; | ||
>value : { [key: string]: ResourceId; } | ||
>key : string | ||
|
||
export default value; | ||
>value : { [key: string]: ResourceId; } | ||
} | ||
|
||
=== /a.ts === | ||
import strings from './hello.locstring.json'; | ||
>strings : { hello: number; } | ||
|
||
strings.hello; | ||
>strings.hello : number | ||
>strings : { hello: number; } | ||
>hello : number | ||
|
19 changes: 19 additions & 0 deletions
19
tests/cases/compiler/moduleResolutionWithExtensions_jsonOverwrite.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @resolveJsonModule: true | ||
// @traceResolution: true | ||
// @esModuleInterop: true | ||
|
||
|
||
// @Filename: /hello.locstring.json | ||
{ "hello": "Hello World" } | ||
|
||
// @Filename: /types.d.ts | ||
type ResourceId = string & { __ResourceId: void }; | ||
declare module "*.locstring.json" { | ||
const value: { [key: string]: ResourceId }; | ||
export default value; | ||
} | ||
|
||
// @Filename: /a.ts | ||
import strings from './hello.locstring.json'; | ||
|
||
strings.hello; |
25 changes: 25 additions & 0 deletions
25
tests/cases/compiler/moduleResolutionWithExtensions_jsonOverwrite2.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// @resolveJsonModule: true | ||
// @traceResolution: true | ||
// @esModuleInterop: true | ||
|
||
|
||
// @Filename: /hello.locstring.json | ||
{ "hello": "Hello World" } | ||
|
||
// @Filename: /hello.locstring.json.d.ts | ||
declare const _default: { | ||
hello: number; | ||
}; | ||
export default _default; | ||
|
||
// @Filename: /types.d.ts | ||
type ResourceId = string & { __ResourceId: void }; | ||
declare module "*.locstring.json" { | ||
const value: { [key: string]: ResourceId }; | ||
export default value; | ||
} | ||
|
||
// @Filename: /a.ts | ||
import strings from './hello.locstring.json'; | ||
|
||
strings.hello; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would the same be true for
.d.ts
contained innode_modules
? would.d.ts
fromnode_modules
"win" over the local override?