diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index df45bdc1a6008..0ba770c6764e1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6249,7 +6249,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return true; } if (requiresAddingUndefined && annotationType) { - annotationType = getOptionalType(annotationType, !isParameter(node)); + annotationType = addOptionality(annotationType, !isParameter(node)); } return !!annotationType && typeNodeIsEquivalentToType(node, type, annotationType) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type); }, diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.js b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.js new file mode 100644 index 0000000000000..fcd8a982b4615 --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.js @@ -0,0 +1,48 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts] //// + +//// [createApi.ts] +type Id = { + [K in keyof T]: T[K]; +} & {}; + +export declare function createApi(_: { endpoints: Definitions }): { + [K in keyof Definitions as `use${Capitalize}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 = { + [K in keyof T]: T[K]; +} & {}; +export declare function createApi(_: { + endpoints: Definitions; +}): { + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; + originalArgs?: undefined; + }>; +}; +export {}; +//// [index.d.ts] +export declare const useTestQuery: () => { + status: "uninitialized"; + originalArgs?: undefined; +}; diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.symbols b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.symbols new file mode 100644 index 0000000000000..085152b6aedec --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.symbols @@ -0,0 +1,63 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts] //// + +=== createApi.ts === +type Id = { +>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(_: { 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}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)) + diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.types b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.types new file mode 100644 index 0000000000000..6037c9c4e7342 --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.types @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts] //// + +=== createApi.ts === +type Id = { +>Id : { [K in keyof T]: T[K]; } +> : ^^^ ^^^^^^^^^^^^^^^^^^^^^ + + [K in keyof T]: T[K]; +} & {}; + +export declare function createApi(_: { endpoints: Definitions }): { +>createApi : (_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ status: "uninitialized"; originalArgs?: undefined; }>; } +> : ^ ^^ ^^ ^^^^^ +>_ : { endpoints: Definitions; } +> : ^^^^^^^^^^^^^ ^^^ +>endpoints : Definitions +> : ^^^^^^^^^^^ + + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; +>status : "uninitialized" +> : ^^^^^^^^^^^^^^^ + + originalArgs?: undefined; +>originalArgs : undefined +> : ^^^^^^^^^ + + }>; +}; + +=== index.ts === +import { createApi } from "./createApi"; +>createApi : (_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize}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 : (_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize}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; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ + diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.js b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.js new file mode 100644 index 0000000000000..e677e091d747e --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.js @@ -0,0 +1,48 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts] //// + +//// [createApi.ts] +type Id = { + [K in keyof T]: T[K]; +} & {}; + +export declare function createApi(_: { endpoints: Definitions }): { + [K in keyof Definitions as `use${Capitalize}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 = { + [K in keyof T]: T[K]; +} & {}; +export declare function createApi(_: { + endpoints: Definitions; +}): { + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; + originalArgs?: any[]; + }>; +}; +export {}; +//// [index.d.ts] +export declare const useTestQuery: () => { + status: "uninitialized"; + originalArgs?: any[]; +}; diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.symbols b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.symbols new file mode 100644 index 0000000000000..cca1208d49189 --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.symbols @@ -0,0 +1,63 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts] //// + +=== createApi.ts === +type Id = { +>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(_: { 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}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)) + diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.types b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.types new file mode 100644 index 0000000000000..c6b38f9716c0a --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.types @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts] //// + +=== createApi.ts === +type Id = { +>Id : { [K in keyof T]: T[K]; } +> : ^^^ ^^^^^^^^^^^^^^^^^^^^^ + + [K in keyof T]: T[K]; +} & {}; + +export declare function createApi(_: { endpoints: Definitions }): { +>createApi : (_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ status: "uninitialized"; originalArgs?: any[]; }>; } +> : ^ ^^ ^^ ^^^^^ +>_ : { endpoints: Definitions; } +> : ^^^^^^^^^^^^^ ^^^ +>endpoints : Definitions +> : ^^^^^^^^^^^ + + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; +>status : "uninitialized" +> : ^^^^^^^^^^^^^^^ + + originalArgs?: any[]; +>originalArgs : any[] +> : ^^^^^ + + }>; +}; + +=== index.ts === +import { createApi } from "./createApi"; +>createApi : (_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize}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 : (_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize}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[]; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ + diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.js b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.js new file mode 100644 index 0000000000000..6e11f34b52877 --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.js @@ -0,0 +1,48 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.ts] //// + +//// [createApi.ts] +type Id = { + [K in keyof T]: T[K]; +} & {}; + +export declare function createApi(_: { endpoints: Definitions }): { + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; + originalArgs?: never; + }>; +}; + +//// [index.ts] +import { createApi } from "./createApi"; + +const slice = createApi({ + endpoints: { + test: { + url: `/user`, + }, + }, +}); + +export const { useTestQuery } = slice; + + + + +//// [createApi.d.ts] +type Id = { + [K in keyof T]: T[K]; +} & {}; +export declare function createApi(_: { + endpoints: Definitions; +}): { + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; + originalArgs?: never; + }>; +}; +export {}; +//// [index.d.ts] +export declare const useTestQuery: () => { + status: "uninitialized"; + originalArgs?: never; +}; diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.symbols b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.symbols new file mode 100644 index 0000000000000..bf7ad1bab1421 --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.symbols @@ -0,0 +1,63 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.ts] //// + +=== createApi.ts === +type Id = { +>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(_: { 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}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?: never; +>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)) + diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.types b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.types new file mode 100644 index 0000000000000..f1bd8df7f79f6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.types @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.ts] //// + +=== createApi.ts === +type Id = { +>Id : { [K in keyof T]: T[K]; } +> : ^^^ ^^^^^^^^^^^^^^^^^^^^^ + + [K in keyof T]: T[K]; +} & {}; + +export declare function createApi(_: { endpoints: Definitions }): { +>createApi : (_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ status: "uninitialized"; originalArgs?: never; }>; } +> : ^ ^^ ^^ ^^^^^ +>_ : { endpoints: Definitions; } +> : ^^^^^^^^^^^^^ ^^^ +>endpoints : Definitions +> : ^^^^^^^^^^^ + + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; +>status : "uninitialized" +> : ^^^^^^^^^^^^^^^ + + originalArgs?: never; +>originalArgs : never +> : ^^^^^ + + }>; +}; + +=== index.ts === +import { createApi } from "./createApi"; +>createApi : (_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize}Query`]: () => { status: "uninitialized"; originalArgs?: never; }; } +> : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^ + +const slice = createApi({ +>slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: never; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ +>createApi({ endpoints: { test: { url: `/user`, }, },}) : { useTestQuery: () => { status: "uninitialized"; originalArgs?: never; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ +>createApi : (_: { endpoints: Definitions; }) => { [K in keyof Definitions as `use${Capitalize}Query`]: () => { status: "uninitialized"; originalArgs?: never; }; } +> : ^ ^^ ^^ ^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^ +>{ 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?: never; } +> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^ +>slice : { useTestQuery: () => { status: "uninitialized"; originalArgs?: never; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^ + diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.js b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.js new file mode 100644 index 0000000000000..4f4ef2d3066e1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts] //// + +//// [declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts] +type InputType = { enable_member_receipts?: boolean }; +type AsEmptyObject = { [K in keyof T]?: undefined }; + +export const test = { + ...({} as AsEmptyObject), +}; + + + + +//// [declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.d.ts] +export declare const test: { + enable_member_receipts?: undefined; +}; diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.symbols b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.symbols new file mode 100644 index 0000000000000..b032cfac5e39b --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.symbols @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts] //// + +=== declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts === +type InputType = { enable_member_receipts?: boolean }; +>InputType : Symbol(InputType, Decl(declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts, 0, 0)) +>enable_member_receipts : Symbol(enable_member_receipts, Decl(declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts, 0, 18)) + +type AsEmptyObject = { [K in keyof T]?: undefined }; +>AsEmptyObject : Symbol(AsEmptyObject, Decl(declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts, 0, 54)) +>T : Symbol(T, Decl(declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts, 1, 19)) +>K : Symbol(K, Decl(declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts, 1, 27)) +>T : Symbol(T, Decl(declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts, 1, 19)) + +export const test = { +>test : Symbol(test, Decl(declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts, 3, 12)) + + ...({} as AsEmptyObject), +>AsEmptyObject : Symbol(AsEmptyObject, Decl(declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts, 0, 54)) +>InputType : Symbol(InputType, Decl(declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts, 0, 0)) + +}; + diff --git a/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.types b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.types new file mode 100644 index 0000000000000..9f902fa6dda7f --- /dev/null +++ b/tests/baselines/reference/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.types @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts] //// + +=== declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts === +type InputType = { enable_member_receipts?: boolean }; +>InputType : InputType +> : ^^^^^^^^^ +>enable_member_receipts : boolean +> : ^^^^^^^ + +type AsEmptyObject = { [K in keyof T]?: undefined }; +>AsEmptyObject : AsEmptyObject +> : ^^^^^^^^^^^^^^^^ + +export const test = { +>test : { enable_member_receipts?: undefined; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ ...({} as AsEmptyObject),} : { enable_member_receipts?: undefined; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + ...({} as AsEmptyObject), +>({} as AsEmptyObject) : AsEmptyObject +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>{} as AsEmptyObject : AsEmptyObject +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>{} : {} +> : ^^ + +}; + diff --git a/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts b/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts new file mode 100644 index 0000000000000..8f0f6b5ae9bfb --- /dev/null +++ b/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks1.ts @@ -0,0 +1,30 @@ +// @strictNullChecks: false +// @declaration: true +// @emitDeclarationOnly: true + +// @filename: createApi.ts + +type Id = { + [K in keyof T]: T[K]; +} & {}; + +export declare function createApi(_: { endpoints: Definitions }): { + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; + originalArgs?: undefined; + }>; +}; + +// @filename: index.ts + +import { createApi } from "./createApi"; + +const slice = createApi({ + endpoints: { + test: { + url: `/user`, + }, + }, +}); + +export const { useTestQuery } = slice; diff --git a/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts b/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts new file mode 100644 index 0000000000000..5add666bcbabe --- /dev/null +++ b/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks2.ts @@ -0,0 +1,30 @@ +// @strictNullChecks: false +// @declaration: true +// @emitDeclarationOnly: true + +// @filename: createApi.ts + +type Id = { + [K in keyof T]: T[K]; +} & {}; + +export declare function createApi(_: { endpoints: Definitions }): { + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; + originalArgs?: any[]; + }>; +}; + +// @filename: index.ts + +import { createApi } from "./createApi"; + +const slice = createApi({ + endpoints: { + test: { + url: `/user`, + }, + }, +}); + +export const { useTestQuery } = slice; diff --git a/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.ts b/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.ts new file mode 100644 index 0000000000000..b9320bc838046 --- /dev/null +++ b/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks3.ts @@ -0,0 +1,30 @@ +// @strictNullChecks: false +// @declaration: true +// @emitDeclarationOnly: true + +// @filename: createApi.ts + +type Id = { + [K in keyof T]: T[K]; +} & {}; + +export declare function createApi(_: { endpoints: Definitions }): { + [K in keyof Definitions as `use${Capitalize}Query`]: () => Id<{ + status: "uninitialized"; + originalArgs?: never; + }>; +}; + +// @filename: index.ts + +import { createApi } from "./createApi"; + +const slice = createApi({ + endpoints: { + test: { + url: `/user`, + }, + }, +}); + +export const { useTestQuery } = slice; diff --git a/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts b/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts new file mode 100644 index 0000000000000..170989a6b8d4a --- /dev/null +++ b/tests/cases/compiler/declarationEmitOptionalMappedTypePropertyNoStrictNullChecks4.ts @@ -0,0 +1,10 @@ +// @strictNullChecks: false +// @declaration: true +// @emitDeclarationOnly: true + +type InputType = { enable_member_receipts?: boolean }; +type AsEmptyObject = { [K in keyof T]?: undefined }; + +export const test = { + ...({} as AsEmptyObject), +};