Skip to content

Commit 7aa63df

Browse files
🤖 Pick PR #60393 (Don't try to add an implicit undefi...) into release-5.7 (#60825)
Co-authored-by: Mateusz BurzyÅ„ski <[email protected]>
1 parent 9df7c36 commit 7aa63df

17 files changed

+721
-1
lines changed

‎src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6249,7 +6249,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
62496249
return true;
62506250
}
62516251
if (requiresAddingUndefined && annotationType) {
6252-
annotationType = getOptionalType(annotationType, !isParameter(node));
6252+
annotationType = addOptionality(annotationType, !isParameter(node));
62536253
}
62546254
return !!annotationType && typeNodeIsEquivalentToType(node, type, annotationType) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type);
62556255
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts] ////
2+
3+
//// [createApi.ts]
4+
type Id<T> = {
5+
[K in keyof T]: T[K];
6+
} & {};
7+
8+
export declare function createApi<Definitions>(_: { endpoints: Definitions }): {
9+
[K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{
10+
status: "uninitialized";
11+
originalArgs?: undefined;
12+
}>;
13+
};
14+
15+
//// [index.ts]
16+
import { createApi } from "./createApi";
17+
18+
const slice = createApi({
19+
endpoints: {
20+
test: {
21+
url: `/user`,
22+
},
23+
},
24+
});
25+
26+
export const { useTestQuery } = slice;
27+
28+
29+
30+
31+
//// [createApi.d.ts]
32+
type Id<T> = {
33+
[K in keyof T]: T[K];
34+
} & {};
35+
export declare function createApi<Definitions>(_: {
36+
endpoints: Definitions;
37+
}): {
38+
[K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{
39+
status: "uninitialized";
40+
originalArgs?: undefined;
41+
}>;
42+
};
43+
export {};
44+
//// [index.d.ts]
45+
export declare const useTestQuery: () => {
46+
status: "uninitialized";
47+
originalArgs?: undefined;
48+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts] ////
2+
3+
=== createApi.ts ===
4+
type Id<T> = {
5+
>Id : Symbol(Id, Decl(createApi.ts, 0, 0))
6+
>T : Symbol(T, Decl(createApi.ts, 0, 8))
7+
8+
[K in keyof T]: T[K];
9+
>K : Symbol(K, Decl(createApi.ts, 1, 3))
10+
>T : Symbol(T, Decl(createApi.ts, 0, 8))
11+
>T : Symbol(T, Decl(createApi.ts, 0, 8))
12+
>K : Symbol(K, Decl(createApi.ts, 1, 3))
13+
14+
} & {};
15+
16+
export declare function createApi<Definitions>(_: { endpoints: Definitions }): {
17+
>createApi : Symbol(createApi, Decl(createApi.ts, 2, 7))
18+
>Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34))
19+
>_ : Symbol(_, Decl(createApi.ts, 4, 47))
20+
>endpoints : Symbol(endpoints, Decl(createApi.ts, 4, 51))
21+
>Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34))
22+
23+
[K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{
24+
>K : Symbol(K, Decl(createApi.ts, 5, 3))
25+
>Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34))
26+
>Capitalize : Symbol(Capitalize, Decl(lib.es5.d.ts, --, --))
27+
>K : Symbol(K, Decl(createApi.ts, 5, 3))
28+
>Id : Symbol(Id, Decl(createApi.ts, 0, 0))
29+
30+
status: "uninitialized";
31+
>status : Symbol(status, Decl(createApi.ts, 5, 77))
32+
33+
originalArgs?: undefined;
34+
>originalArgs : Symbol(originalArgs, Decl(createApi.ts, 6, 28))
35+
36+
}>;
37+
};
38+
39+
=== index.ts ===
40+
import { createApi } from "./createApi";
41+
>createApi : Symbol(createApi, Decl(index.ts, 0, 8))
42+
43+
const slice = createApi({
44+
>slice : Symbol(slice, Decl(index.ts, 2, 5))
45+
>createApi : Symbol(createApi, Decl(index.ts, 0, 8))
46+
47+
endpoints: {
48+
>endpoints : Symbol(endpoints, Decl(index.ts, 2, 25))
49+
50+
test: {
51+
>test : Symbol(test, Decl(index.ts, 3, 14))
52+
53+
url: `/user`,
54+
>url : Symbol(url, Decl(index.ts, 4, 11))
55+
56+
},
57+
},
58+
});
59+
60+
export const { useTestQuery } = slice;
61+
>useTestQuery : Symbol(useTestQuery, Decl(index.ts, 10, 14))
62+
>slice : Symbol(slice, Decl(index.ts, 2, 5))
63+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts] ////
2+
3+
=== createApi.ts ===
4+
type Id<T> = {
5+
>Id : { [K in keyof T]: T[K]; }
6+
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^
7+
8+
[K in keyof T]: T[K];
9+
} & {};
10+
11+
export declare function createApi<Definitions>(_: { endpoints: Definitions }): {
12+
>createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ status: "uninitialized"; originalArgs?: undefined; }>; }
13+
> : ^ ^^ ^^ ^^^^^
14+
>_ : { endpoints: Definitions; }
15+
> : ^^^^^^^^^^^^^ ^^^
16+
>endpoints : Definitions
17+
> : ^^^^^^^^^^^
18+
19+
[K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{
20+
status: "uninitialized";
21+
>status : "uninitialized"
22+
> : ^^^^^^^^^^^^^^^
23+
24+
originalArgs?: undefined;
25+
>originalArgs : undefined
26+
> : ^^^^^^^^^
27+
28+
}>;
29+
};
30+
31+
=== index.ts ===
32+
import { createApi } from "./createApi";
33+
>createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => { status: "uninitialized"; originalArgs?: undefined; }; }
34+
> : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^
35+
36+
const slice = createApi({
37+
>slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: undefined; }; }
38+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^
39+
>createApi({ endpoints: { test: { url: `/user`, }, },}) : { useTestQuery: () => { status: "uninitialized"; originalArgs?: undefined; }; }
40+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^
41+
>createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => { status: "uninitialized"; originalArgs?: undefined; }; }
42+
> : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^
43+
>{ endpoints: { test: { url: `/user`, }, },} : { endpoints: { test: { url: string; }; }; }
44+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45+
46+
endpoints: {
47+
>endpoints : { test: { url: string; }; }
48+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
>{ test: { url: `/user`, }, } : { test: { url: string; }; }
50+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
51+
52+
test: {
53+
>test : { url: string; }
54+
> : ^^^^^^^^^^^^^^^^
55+
>{ url: `/user`, } : { url: string; }
56+
> : ^^^^^^^^^^^^^^^^
57+
58+
url: `/user`,
59+
>url : string
60+
> : ^^^^^^
61+
>`/user` : "/user"
62+
> : ^^^^^^^
63+
64+
},
65+
},
66+
});
67+
68+
export const { useTestQuery } = slice;
69+
>useTestQuery : () => { status: "uninitialized"; originalArgs?: undefined; }
70+
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^
71+
>slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: undefined; }; }
72+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^
73+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts] ////
2+
3+
//// [createApi.ts]
4+
type Id<T> = {
5+
[K in keyof T]: T[K];
6+
} & {};
7+
8+
export declare function createApi<Definitions>(_: { endpoints: Definitions }): {
9+
[K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{
10+
status: "uninitialized";
11+
originalArgs?: any[];
12+
}>;
13+
};
14+
15+
//// [index.ts]
16+
import { createApi } from "./createApi";
17+
18+
const slice = createApi({
19+
endpoints: {
20+
test: {
21+
url: `/user`,
22+
},
23+
},
24+
});
25+
26+
export const { useTestQuery } = slice;
27+
28+
29+
30+
31+
//// [createApi.d.ts]
32+
type Id<T> = {
33+
[K in keyof T]: T[K];
34+
} & {};
35+
export declare function createApi<Definitions>(_: {
36+
endpoints: Definitions;
37+
}): {
38+
[K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{
39+
status: "uninitialized";
40+
originalArgs?: any[];
41+
}>;
42+
};
43+
export {};
44+
//// [index.d.ts]
45+
export declare const useTestQuery: () => {
46+
status: "uninitialized";
47+
originalArgs?: any[];
48+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts] ////
2+
3+
=== createApi.ts ===
4+
type Id<T> = {
5+
>Id : Symbol(Id, Decl(createApi.ts, 0, 0))
6+
>T : Symbol(T, Decl(createApi.ts, 0, 8))
7+
8+
[K in keyof T]: T[K];
9+
>K : Symbol(K, Decl(createApi.ts, 1, 3))
10+
>T : Symbol(T, Decl(createApi.ts, 0, 8))
11+
>T : Symbol(T, Decl(createApi.ts, 0, 8))
12+
>K : Symbol(K, Decl(createApi.ts, 1, 3))
13+
14+
} & {};
15+
16+
export declare function createApi<Definitions>(_: { endpoints: Definitions }): {
17+
>createApi : Symbol(createApi, Decl(createApi.ts, 2, 7))
18+
>Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34))
19+
>_ : Symbol(_, Decl(createApi.ts, 4, 47))
20+
>endpoints : Symbol(endpoints, Decl(createApi.ts, 4, 51))
21+
>Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34))
22+
23+
[K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{
24+
>K : Symbol(K, Decl(createApi.ts, 5, 3))
25+
>Definitions : Symbol(Definitions, Decl(createApi.ts, 4, 34))
26+
>Capitalize : Symbol(Capitalize, Decl(lib.es5.d.ts, --, --))
27+
>K : Symbol(K, Decl(createApi.ts, 5, 3))
28+
>Id : Symbol(Id, Decl(createApi.ts, 0, 0))
29+
30+
status: "uninitialized";
31+
>status : Symbol(status, Decl(createApi.ts, 5, 77))
32+
33+
originalArgs?: any[];
34+
>originalArgs : Symbol(originalArgs, Decl(createApi.ts, 6, 28))
35+
36+
}>;
37+
};
38+
39+
=== index.ts ===
40+
import { createApi } from "./createApi";
41+
>createApi : Symbol(createApi, Decl(index.ts, 0, 8))
42+
43+
const slice = createApi({
44+
>slice : Symbol(slice, Decl(index.ts, 2, 5))
45+
>createApi : Symbol(createApi, Decl(index.ts, 0, 8))
46+
47+
endpoints: {
48+
>endpoints : Symbol(endpoints, Decl(index.ts, 2, 25))
49+
50+
test: {
51+
>test : Symbol(test, Decl(index.ts, 3, 14))
52+
53+
url: `/user`,
54+
>url : Symbol(url, Decl(index.ts, 4, 11))
55+
56+
},
57+
},
58+
});
59+
60+
export const { useTestQuery } = slice;
61+
>useTestQuery : Symbol(useTestQuery, Decl(index.ts, 10, 14))
62+
>slice : Symbol(slice, Decl(index.ts, 2, 5))
63+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts] ////
2+
3+
=== createApi.ts ===
4+
type Id<T> = {
5+
>Id : { [K in keyof T]: T[K]; }
6+
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^
7+
8+
[K in keyof T]: T[K];
9+
} & {};
10+
11+
export declare function createApi<Definitions>(_: { endpoints: Definitions }): {
12+
>createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{ status: "uninitialized"; originalArgs?: any[]; }>; }
13+
> : ^ ^^ ^^ ^^^^^
14+
>_ : { endpoints: Definitions; }
15+
> : ^^^^^^^^^^^^^ ^^^
16+
>endpoints : Definitions
17+
> : ^^^^^^^^^^^
18+
19+
[K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => Id<{
20+
status: "uninitialized";
21+
>status : "uninitialized"
22+
> : ^^^^^^^^^^^^^^^
23+
24+
originalArgs?: any[];
25+
>originalArgs : any[]
26+
> : ^^^^^
27+
28+
}>;
29+
};
30+
31+
=== index.ts ===
32+
import { createApi } from "./createApi";
33+
>createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => { status: "uninitialized"; originalArgs?: any[]; }; }
34+
> : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^
35+
36+
const slice = createApi({
37+
>slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: any[]; }; }
38+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^
39+
>createApi({ endpoints: { test: { url: `/user`, }, },}) : { useTestQuery: () => { status: "uninitialized"; originalArgs?: any[]; }; }
40+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^
41+
>createApi : <Definitions>(_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize<K & string>}Query`]: () => { status: "uninitialized"; originalArgs?: any[]; }; }
42+
> : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^
43+
>{ endpoints: { test: { url: `/user`, }, },} : { endpoints: { test: { url: string; }; }; }
44+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45+
46+
endpoints: {
47+
>endpoints : { test: { url: string; }; }
48+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
>{ test: { url: `/user`, }, } : { test: { url: string; }; }
50+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
51+
52+
test: {
53+
>test : { url: string; }
54+
> : ^^^^^^^^^^^^^^^^
55+
>{ url: `/user`, } : { url: string; }
56+
> : ^^^^^^^^^^^^^^^^
57+
58+
url: `/user`,
59+
>url : string
60+
> : ^^^^^^
61+
>`/user` : "/user"
62+
> : ^^^^^^^
63+
64+
},
65+
},
66+
});
67+
68+
export const { useTestQuery } = slice;
69+
>useTestQuery : () => { status: "uninitialized"; originalArgs?: any[]; }
70+
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^
71+
>slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: any[]; }; }
72+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^
73+

0 commit comments

Comments
 (0)