-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Don't try to add an implicit undefined for mapped properties outside of strictNullChecks
#60393
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
Merged
jakebailey
merged 5 commits into
microsoft:main
from
Andarist:fix/no-strict-null-checks-crash-optional-undefined
Dec 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2f4fc4
Don't try to add an implicit undefined for mapped properties outside …
Andarist 93e81c4
Merge remote-tracking branch 'origin/main' into fix/no-strict-null-ch…
Andarist 76c3879
add extra test case
Andarist 07cda04
Merge remote-tracking branch 'origin/main' into fix/no-strict-null-ch…
Andarist 170d9fd
tweak fix
Andarist 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
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.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,48 @@ | ||
| //// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts] //// | ||
|
|
||
| //// [createApi.ts] | ||
| type Id<T> = { | ||
| [K in keyof T]: T[K]; | ||
| } & {}; | ||
|
|
||
| export declare function createApi<Definitions>(_: { endpoints: Definitions }): { | ||
| [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ | ||
| status: "uninitialized"; | ||
| originalArgs?: undefined; | ||
| }>; | ||
| }; | ||
|
|
||
| //// [index.ts] | ||
| import { createApi } from "./createApi"; | ||
|
|
||
| const slice = createApi({ | ||
| endpoints: { | ||
| test: { | ||
| url: `/user`, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const { useTestQuery } = slice; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| //// [createApi.d.ts] | ||
| type Id<T> = { | ||
| [K in keyof T]: T[K]; | ||
| } & {}; | ||
| export declare function createApi<Definitions>(_: { | ||
| endpoints: Definitions; | ||
| }): { | ||
| [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ | ||
| status: "uninitialized"; | ||
| originalArgs?: undefined; | ||
| }>; | ||
| }; | ||
| export {}; | ||
| //// [index.d.ts] | ||
| export declare const useTestQuery: () => { | ||
| status: "uninitialized"; | ||
| originalArgs?: undefined; | ||
| }; |
63 changes: 63 additions & 0 deletions
63
.../baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.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,63 @@ | ||
| //// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts] //// | ||
|
|
||
| === createApi.ts === | ||
| type Id<T> = { | ||
| >Id : Symbol(Id, Decl(createApi.ts, 0, 0)) | ||
| >T : Symbol(T, Decl(createApi.ts, 0, 8)) | ||
|
|
||
| [K in keyof T]: T[K]; | ||
| >K : Symbol(K, Decl(createApi.ts, 1, 3)) | ||
| >T : Symbol(T, Decl(createApi.ts, 0, 8)) | ||
| >T : Symbol(T, Decl(createApi.ts, 0, 8)) | ||
| >K : Symbol(K, Decl(createApi.ts, 1, 3)) | ||
|
|
||
| } & {}; | ||
|
|
||
| export declare function createApi<Definitions>(_: { endpoints: Definitions }): { | ||
| >createApi : Symbol(createApi, Decl(createApi.ts, 2, 7)) | ||
| >Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34)) | ||
| >_ : Symbol(_, Decl(createApi.ts, 4, 47)) | ||
| >endpoints : Symbol(endpoints, Decl(createApi.ts, 4, 51)) | ||
| >Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34)) | ||
|
|
||
| [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ | ||
| >K : Symbol(K, Decl(createApi.ts, 5, 3)) | ||
| >Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34)) | ||
| >Capitalize : Symbol(Capitalize, Decl(lib.es5.d.ts, --, --)) | ||
| >K : Symbol(K, Decl(createApi.ts, 5, 3)) | ||
| >Id : Symbol(Id, Decl(createApi.ts, 0, 0)) | ||
|
|
||
| status: "uninitialized"; | ||
| >status : Symbol(status, Decl(createApi.ts, 5, 77)) | ||
|
|
||
| originalArgs?: undefined; | ||
| >originalArgs : Symbol(originalArgs, Decl(createApi.ts, 6, 28)) | ||
|
|
||
| }>; | ||
| }; | ||
|
|
||
| === index.ts === | ||
| import { createApi } from "./createApi"; | ||
| >createApi : Symbol(createApi, Decl(index.ts, 0, 8)) | ||
|
|
||
| const slice = createApi({ | ||
| >slice : Symbol(slice, Decl(index.ts, 2, 5)) | ||
| >createApi : Symbol(createApi, Decl(index.ts, 0, 8)) | ||
|
|
||
| endpoints: { | ||
| >endpoints : Symbol(endpoints, Decl(index.ts, 2, 25)) | ||
|
|
||
| test: { | ||
| >test : Symbol(test, Decl(index.ts, 3, 14)) | ||
|
|
||
| url: `/user`, | ||
| >url : Symbol(url, Decl(index.ts, 4, 11)) | ||
|
|
||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const { useTestQuery } = slice; | ||
| >useTestQuery : Symbol(useTestQuery, Decl(index.ts, 10, 14)) | ||
| >slice : Symbol(slice, Decl(index.ts, 2, 5)) | ||
|
|
73 changes: 73 additions & 0 deletions
73
tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.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,73 @@ | ||
| //// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts] //// | ||
|
|
||
| === createApi.ts === | ||
| type Id<T> = { | ||
| >Id : { [K in keyof T]: T[K]; } | ||
| > : ^^^ ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| [K in keyof T]: T[K]; | ||
| } & {}; | ||
|
|
||
| export declare function createApi<Definitions>(_: { endpoints: Definitions }): { | ||
| >createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ status: "uninitialized"; originalArgs?: undefined; }>; } | ||
| > : ^ ^^ ^^ ^^^^^ | ||
| >_ : { endpoints: Definitions; } | ||
| > : ^^^^^^^^^^^^^ ^^^ | ||
| >endpoints : Definitions | ||
| > : ^^^^^^^^^^^ | ||
|
|
||
| [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ | ||
| status: "uninitialized"; | ||
| >status : "uninitialized" | ||
| > : ^^^^^^^^^^^^^^^ | ||
|
|
||
| originalArgs?: undefined; | ||
| >originalArgs : undefined | ||
| > : ^^^^^^^^^ | ||
|
|
||
| }>; | ||
| }; | ||
|
|
||
| === index.ts === | ||
| import { createApi } from "./createApi"; | ||
| >createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => { status: "uninitialized"; originalArgs?: undefined; }; } | ||
| > : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^ | ||
|
|
||
| const slice = createApi({ | ||
| >slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: undefined; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ | ||
| >createApi({ endpoints: { test: { url: `/user`, }, },}) : { useTestQuery: () => { status: "uninitialized"; originalArgs?: undefined; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ | ||
| >createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => { status: "uninitialized"; originalArgs?: undefined; }; } | ||
| > : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^ | ||
| >{ endpoints: { test: { url: `/user`, }, },} : { endpoints: { test: { url: string; }; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| endpoints: { | ||
| >endpoints : { test: { url: string; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| >{ test: { url: `/user`, }, } : { test: { url: string; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| test: { | ||
| >test : { url: string; } | ||
| > : ^^^^^^^^^^^^^^^^ | ||
| >{ url: `/user`, } : { url: string; } | ||
| > : ^^^^^^^^^^^^^^^^ | ||
|
|
||
| url: `/user`, | ||
| >url : string | ||
| > : ^^^^^^ | ||
| >`/user` : "/user" | ||
| > : ^^^^^^^ | ||
|
|
||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const { useTestQuery } = slice; | ||
| >useTestQuery : () => { status: "uninitialized"; originalArgs?: undefined; } | ||
| > : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^ | ||
| >slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: undefined; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ | ||
|
|
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.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,48 @@ | ||
| //// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts] //// | ||
|
|
||
| //// [createApi.ts] | ||
| type Id<T> = { | ||
| [K in keyof T]: T[K]; | ||
| } & {}; | ||
|
|
||
| export declare function createApi<Definitions>(_: { endpoints: Definitions }): { | ||
| [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ | ||
| status: "uninitialized"; | ||
| originalArgs?: any[]; | ||
| }>; | ||
| }; | ||
|
|
||
| //// [index.ts] | ||
| import { createApi } from "./createApi"; | ||
|
|
||
| const slice = createApi({ | ||
| endpoints: { | ||
| test: { | ||
| url: `/user`, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const { useTestQuery } = slice; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| //// [createApi.d.ts] | ||
| type Id<T> = { | ||
| [K in keyof T]: T[K]; | ||
| } & {}; | ||
| export declare function createApi<Definitions>(_: { | ||
| endpoints: Definitions; | ||
| }): { | ||
| [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ | ||
| status: "uninitialized"; | ||
| originalArgs?: any[]; | ||
| }>; | ||
| }; | ||
| export {}; | ||
| //// [index.d.ts] | ||
| export declare const useTestQuery: () => { | ||
| status: "uninitialized"; | ||
| originalArgs?: any[]; | ||
| }; |
63 changes: 63 additions & 0 deletions
63
.../baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.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,63 @@ | ||
| //// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts] //// | ||
|
|
||
| === createApi.ts === | ||
| type Id<T> = { | ||
| >Id : Symbol(Id, Decl(createApi.ts, 0, 0)) | ||
| >T : Symbol(T, Decl(createApi.ts, 0, 8)) | ||
|
|
||
| [K in keyof T]: T[K]; | ||
| >K : Symbol(K, Decl(createApi.ts, 1, 3)) | ||
| >T : Symbol(T, Decl(createApi.ts, 0, 8)) | ||
| >T : Symbol(T, Decl(createApi.ts, 0, 8)) | ||
| >K : Symbol(K, Decl(createApi.ts, 1, 3)) | ||
|
|
||
| } & {}; | ||
|
|
||
| export declare function createApi<Definitions>(_: { endpoints: Definitions }): { | ||
| >createApi : Symbol(createApi, Decl(createApi.ts, 2, 7)) | ||
| >Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34)) | ||
| >_ : Symbol(_, Decl(createApi.ts, 4, 47)) | ||
| >endpoints : Symbol(endpoints, Decl(createApi.ts, 4, 51)) | ||
| >Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34)) | ||
|
|
||
| [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ | ||
| >K : Symbol(K, Decl(createApi.ts, 5, 3)) | ||
| >Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34)) | ||
| >Capitalize : Symbol(Capitalize, Decl(lib.es5.d.ts, --, --)) | ||
| >K : Symbol(K, Decl(createApi.ts, 5, 3)) | ||
| >Id : Symbol(Id, Decl(createApi.ts, 0, 0)) | ||
|
|
||
| status: "uninitialized"; | ||
| >status : Symbol(status, Decl(createApi.ts, 5, 77)) | ||
|
|
||
| originalArgs?: any[]; | ||
| >originalArgs : Symbol(originalArgs, Decl(createApi.ts, 6, 28)) | ||
|
|
||
| }>; | ||
| }; | ||
|
|
||
| === index.ts === | ||
| import { createApi } from "./createApi"; | ||
| >createApi : Symbol(createApi, Decl(index.ts, 0, 8)) | ||
|
|
||
| const slice = createApi({ | ||
| >slice : Symbol(slice, Decl(index.ts, 2, 5)) | ||
| >createApi : Symbol(createApi, Decl(index.ts, 0, 8)) | ||
|
|
||
| endpoints: { | ||
| >endpoints : Symbol(endpoints, Decl(index.ts, 2, 25)) | ||
|
|
||
| test: { | ||
| >test : Symbol(test, Decl(index.ts, 3, 14)) | ||
|
|
||
| url: `/user`, | ||
| >url : Symbol(url, Decl(index.ts, 4, 11)) | ||
|
|
||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const { useTestQuery } = slice; | ||
| >useTestQuery : Symbol(useTestQuery, Decl(index.ts, 10, 14)) | ||
| >slice : Symbol(slice, Decl(index.ts, 2, 5)) | ||
|
|
73 changes: 73 additions & 0 deletions
73
tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.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,73 @@ | ||
| //// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts] //// | ||
|
|
||
| === createApi.ts === | ||
| type Id<T> = { | ||
| >Id : { [K in keyof T]: T[K]; } | ||
| > : ^^^ ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| [K in keyof T]: T[K]; | ||
| } & {}; | ||
|
|
||
| export declare function createApi<Definitions>(_: { endpoints: Definitions }): { | ||
| >createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ status: "uninitialized"; originalArgs?: any[]; }>; } | ||
| > : ^ ^^ ^^ ^^^^^ | ||
| >_ : { endpoints: Definitions; } | ||
| > : ^^^^^^^^^^^^^ ^^^ | ||
| >endpoints : Definitions | ||
| > : ^^^^^^^^^^^ | ||
|
|
||
| [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ | ||
| status: "uninitialized"; | ||
| >status : "uninitialized" | ||
| > : ^^^^^^^^^^^^^^^ | ||
|
|
||
| originalArgs?: any[]; | ||
| >originalArgs : any[] | ||
| > : ^^^^^ | ||
|
|
||
| }>; | ||
| }; | ||
|
|
||
| === index.ts === | ||
| import { createApi } from "./createApi"; | ||
| >createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => { status: "uninitialized"; originalArgs?: any[]; }; } | ||
| > : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^ | ||
|
|
||
| const slice = createApi({ | ||
| >slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: any[]; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ | ||
| >createApi({ endpoints: { test: { url: `/user`, }, },}) : { useTestQuery: () => { status: "uninitialized"; originalArgs?: any[]; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ | ||
| >createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => { status: "uninitialized"; originalArgs?: any[]; }; } | ||
| > : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^ | ||
| >{ endpoints: { test: { url: `/user`, }, },} : { endpoints: { test: { url: string; }; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| endpoints: { | ||
| >endpoints : { test: { url: string; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| >{ test: { url: `/user`, }, } : { test: { url: string; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| test: { | ||
| >test : { url: string; } | ||
| > : ^^^^^^^^^^^^^^^^ | ||
| >{ url: `/user`, } : { url: string; } | ||
| > : ^^^^^^^^^^^^^^^^ | ||
|
|
||
| url: `/user`, | ||
| >url : string | ||
| > : ^^^^^^ | ||
| >`/user` : "/user" | ||
| > : ^^^^^^^ | ||
|
|
||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const { useTestQuery } = slice; | ||
| >useTestQuery : () => { status: "uninitialized"; originalArgs?: any[]; } | ||
| > : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^ | ||
| >slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: any[]; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ | ||
|
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.