From 7a744f7f2b1364c5c0a62bb9218259aba3a48309 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 20 Mar 2023 09:03:47 -0700 Subject: [PATCH 1/2] Add bad test --- .../templateLiteralIntersection4.errors.txt | 25 +++++++++ .../reference/templateLiteralIntersection4.js | 24 ++++++++ .../templateLiteralIntersection4.symbols | 56 +++++++++++++++++++ .../templateLiteralIntersection4.types | 42 ++++++++++++++ .../compiler/templateLiteralIntersection4.ts | 17 ++++++ 5 files changed, 164 insertions(+) create mode 100644 tests/baselines/reference/templateLiteralIntersection4.errors.txt create mode 100644 tests/baselines/reference/templateLiteralIntersection4.js create mode 100644 tests/baselines/reference/templateLiteralIntersection4.symbols create mode 100644 tests/baselines/reference/templateLiteralIntersection4.types create mode 100644 tests/cases/compiler/templateLiteralIntersection4.ts diff --git a/tests/baselines/reference/templateLiteralIntersection4.errors.txt b/tests/baselines/reference/templateLiteralIntersection4.errors.txt new file mode 100644 index 0000000000000..1c9d5216e6c16 --- /dev/null +++ b/tests/baselines/reference/templateLiteralIntersection4.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/templateLiteralIntersection4.ts(12,19): error TS2339: Property 'useUsername' does not exist on type 'StoreUtils<{ username: string; age: number; }>'. +tests/cases/compiler/templateLiteralIntersection4.ts(12,32): error TS2339: Property 'useAge' does not exist on type 'StoreUtils<{ username: string; age: number; }>'. + + +==== tests/cases/compiler/templateLiteralIntersection4.ts (2 errors) ==== + type StateHook = () => [S, unknown]; + + type StoreUtils = Omit<{ + [K in keyof Store as `use${Capitalize}`]: StateHook + }, 'useStore'> & { + Provider: unknown, + useStore: StateHook + }; + + declare function createStore(store: Store): StoreUtils; + + const { Provider, useUsername, useAge, useStore } = createStore({ + ~~~~~~~~~~~ +!!! error TS2339: Property 'useUsername' does not exist on type 'StoreUtils<{ username: string; age: number; }>'. + ~~~~~~ +!!! error TS2339: Property 'useAge' does not exist on type 'StoreUtils<{ username: string; age: number; }>'. + username: "Aral", + age: 31 + }); + \ No newline at end of file diff --git a/tests/baselines/reference/templateLiteralIntersection4.js b/tests/baselines/reference/templateLiteralIntersection4.js new file mode 100644 index 0000000000000..76d4586e42937 --- /dev/null +++ b/tests/baselines/reference/templateLiteralIntersection4.js @@ -0,0 +1,24 @@ +//// [templateLiteralIntersection4.ts] +type StateHook = () => [S, unknown]; + +type StoreUtils = Omit<{ + [K in keyof Store as `use${Capitalize}`]: StateHook +}, 'useStore'> & { + Provider: unknown, + useStore: StateHook +}; + +declare function createStore(store: Store): StoreUtils; + +const { Provider, useUsername, useAge, useStore } = createStore({ + username: "Aral", + age: 31 +}); + + +//// [templateLiteralIntersection4.js] +"use strict"; +var _a = createStore({ + username: "Aral", + age: 31 +}), Provider = _a.Provider, useUsername = _a.useUsername, useAge = _a.useAge, useStore = _a.useStore; diff --git a/tests/baselines/reference/templateLiteralIntersection4.symbols b/tests/baselines/reference/templateLiteralIntersection4.symbols new file mode 100644 index 0000000000000..f69dc5d67a0a0 --- /dev/null +++ b/tests/baselines/reference/templateLiteralIntersection4.symbols @@ -0,0 +1,56 @@ +=== tests/cases/compiler/templateLiteralIntersection4.ts === +type StateHook = () => [S, unknown]; +>StateHook : Symbol(StateHook, Decl(templateLiteralIntersection4.ts, 0, 0)) +>S : Symbol(S, Decl(templateLiteralIntersection4.ts, 0, 15)) +>S : Symbol(S, Decl(templateLiteralIntersection4.ts, 0, 15)) + +type StoreUtils = Omit<{ +>StoreUtils : Symbol(StoreUtils, Decl(templateLiteralIntersection4.ts, 0, 39)) +>Store : Symbol(Store, Decl(templateLiteralIntersection4.ts, 2, 16)) +>K : Symbol(K, Decl(templateLiteralIntersection4.ts, 2, 33)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) + + [K in keyof Store as `use${Capitalize}`]: StateHook +>K : Symbol(K, Decl(templateLiteralIntersection4.ts, 3, 5)) +>Store : Symbol(Store, Decl(templateLiteralIntersection4.ts, 2, 16)) +>Capitalize : Symbol(Capitalize, Decl(lib.es5.d.ts, --, --)) +>K : Symbol(K, Decl(templateLiteralIntersection4.ts, 3, 5)) +>StateHook : Symbol(StateHook, Decl(templateLiteralIntersection4.ts, 0, 0)) +>Store : Symbol(Store, Decl(templateLiteralIntersection4.ts, 2, 16)) +>K : Symbol(K, Decl(templateLiteralIntersection4.ts, 3, 5)) + +}, 'useStore'> & { + Provider: unknown, +>Provider : Symbol(Provider, Decl(templateLiteralIntersection4.ts, 4, 18)) + + useStore: StateHook +>useStore : Symbol(useStore, Decl(templateLiteralIntersection4.ts, 5, 20)) +>StateHook : Symbol(StateHook, Decl(templateLiteralIntersection4.ts, 0, 0)) +>Store : Symbol(Store, Decl(templateLiteralIntersection4.ts, 2, 16)) + +}; + +declare function createStore(store: Store): StoreUtils; +>createStore : Symbol(createStore, Decl(templateLiteralIntersection4.ts, 7, 2)) +>Store : Symbol(Store, Decl(templateLiteralIntersection4.ts, 9, 29)) +>K : Symbol(K, Decl(templateLiteralIntersection4.ts, 9, 46)) +>store : Symbol(store, Decl(templateLiteralIntersection4.ts, 9, 65)) +>Store : Symbol(Store, Decl(templateLiteralIntersection4.ts, 9, 29)) +>StoreUtils : Symbol(StoreUtils, Decl(templateLiteralIntersection4.ts, 0, 39)) +>Store : Symbol(Store, Decl(templateLiteralIntersection4.ts, 9, 29)) + +const { Provider, useUsername, useAge, useStore } = createStore({ +>Provider : Symbol(Provider, Decl(templateLiteralIntersection4.ts, 11, 7)) +>useUsername : Symbol(useUsername, Decl(templateLiteralIntersection4.ts, 11, 17)) +>useAge : Symbol(useAge, Decl(templateLiteralIntersection4.ts, 11, 30)) +>useStore : Symbol(useStore, Decl(templateLiteralIntersection4.ts, 11, 38)) +>createStore : Symbol(createStore, Decl(templateLiteralIntersection4.ts, 7, 2)) + + username: "Aral", +>username : Symbol(username, Decl(templateLiteralIntersection4.ts, 11, 65)) + + age: 31 +>age : Symbol(age, Decl(templateLiteralIntersection4.ts, 12, 19)) + +}); + diff --git a/tests/baselines/reference/templateLiteralIntersection4.types b/tests/baselines/reference/templateLiteralIntersection4.types new file mode 100644 index 0000000000000..9524ed31bf9a5 --- /dev/null +++ b/tests/baselines/reference/templateLiteralIntersection4.types @@ -0,0 +1,42 @@ +=== tests/cases/compiler/templateLiteralIntersection4.ts === +type StateHook = () => [S, unknown]; +>StateHook : StateHook + +type StoreUtils = Omit<{ +>StoreUtils : StoreUtils +>K : string + + [K in keyof Store as `use${Capitalize}`]: StateHook +}, 'useStore'> & { + Provider: unknown, +>Provider : unknown + + useStore: StateHook +>useStore : StateHook + +}; + +declare function createStore(store: Store): StoreUtils; +>createStore : (store: Store) => StoreUtils +>K : string +>store : Store + +const { Provider, useUsername, useAge, useStore } = createStore({ +>Provider : unknown +>useUsername : any +>useAge : any +>useStore : StateHook<{ username: string; age: number; }> +>createStore({ username: "Aral", age: 31}) : StoreUtils<{ username: string; age: number; }> +>createStore : (store: Store) => StoreUtils +>{ username: "Aral", age: 31} : { username: string; age: number; } + + username: "Aral", +>username : string +>"Aral" : "Aral" + + age: 31 +>age : number +>31 : 31 + +}); + diff --git a/tests/cases/compiler/templateLiteralIntersection4.ts b/tests/cases/compiler/templateLiteralIntersection4.ts new file mode 100644 index 0000000000000..95c1e620cecd8 --- /dev/null +++ b/tests/cases/compiler/templateLiteralIntersection4.ts @@ -0,0 +1,17 @@ +// @strict: true + +type StateHook = () => [S, unknown]; + +type StoreUtils = Omit<{ + [K in keyof Store as `use${Capitalize}`]: StateHook +}, 'useStore'> & { + Provider: unknown, + useStore: StateHook +}; + +declare function createStore(store: Store): StoreUtils; + +const { Provider, useUsername, useAge, useStore } = createStore({ + username: "Aral", + age: 31 +}); From 8a6843f6c999034ae6c23b40ac1107d011c1b6ab Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 20 Mar 2023 09:12:14 -0700 Subject: [PATCH 2/2] Remove unneeded handling of intersections in getStringMappingType --- src/compiler/checker.ts | 1 - .../templateLiteralIntersection3.types | 4 +-- .../templateLiteralIntersection4.errors.txt | 25 ------------------- .../templateLiteralIntersection4.types | 4 +-- 4 files changed, 4 insertions(+), 30 deletions(-) delete mode 100644 tests/baselines/reference/templateLiteralIntersection4.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b975b9848853d..80511a5adf67f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17113,7 +17113,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getStringMappingType(symbol: Symbol, type: Type): Type { return type.flags & (TypeFlags.Union | TypeFlags.Never) ? mapType(type, t => getStringMappingType(symbol, t)) : - type.flags & TypeFlags.Intersection ? getIntersectionType(map((type as IntersectionType).types, t => getStringMappingType(symbol, t))) : type.flags & TypeFlags.StringLiteral ? getStringLiteralType(applyStringMapping(symbol, (type as StringLiteralType).value)) : type.flags & TypeFlags.TemplateLiteral ? getTemplateLiteralType(...applyTemplateStringMapping(symbol, (type as TemplateLiteralType).texts, (type as TemplateLiteralType).types)) : // Mapping> === Mapping diff --git a/tests/baselines/reference/templateLiteralIntersection3.types b/tests/baselines/reference/templateLiteralIntersection3.types index 4c89a8c82c2f7..391caac66ce6b 100644 --- a/tests/baselines/reference/templateLiteralIntersection3.types +++ b/tests/baselines/reference/templateLiteralIntersection3.types @@ -29,12 +29,12 @@ options1[`foo/${path}`] = false; // Lowercase<`foo/${Path}`> => `foo/${Lowercase}` declare const lowercasePath: Lowercase<`foo/${Path}`>; ->lowercasePath : `foo/${Lowercase & { _pathBrand: any; }}` +>lowercasePath : `foo/${Lowercase<`${Path}`>}` options1[lowercasePath] = false; >options1[lowercasePath] = false : false >options1[lowercasePath] : boolean >options1 : { prop: number; } & { [k: string]: boolean; } ->lowercasePath : `foo/${Lowercase & { _pathBrand: any; }}` +>lowercasePath : `foo/${Lowercase<`${Path}`>}` >false : false diff --git a/tests/baselines/reference/templateLiteralIntersection4.errors.txt b/tests/baselines/reference/templateLiteralIntersection4.errors.txt deleted file mode 100644 index 1c9d5216e6c16..0000000000000 --- a/tests/baselines/reference/templateLiteralIntersection4.errors.txt +++ /dev/null @@ -1,25 +0,0 @@ -tests/cases/compiler/templateLiteralIntersection4.ts(12,19): error TS2339: Property 'useUsername' does not exist on type 'StoreUtils<{ username: string; age: number; }>'. -tests/cases/compiler/templateLiteralIntersection4.ts(12,32): error TS2339: Property 'useAge' does not exist on type 'StoreUtils<{ username: string; age: number; }>'. - - -==== tests/cases/compiler/templateLiteralIntersection4.ts (2 errors) ==== - type StateHook = () => [S, unknown]; - - type StoreUtils = Omit<{ - [K in keyof Store as `use${Capitalize}`]: StateHook - }, 'useStore'> & { - Provider: unknown, - useStore: StateHook - }; - - declare function createStore(store: Store): StoreUtils; - - const { Provider, useUsername, useAge, useStore } = createStore({ - ~~~~~~~~~~~ -!!! error TS2339: Property 'useUsername' does not exist on type 'StoreUtils<{ username: string; age: number; }>'. - ~~~~~~ -!!! error TS2339: Property 'useAge' does not exist on type 'StoreUtils<{ username: string; age: number; }>'. - username: "Aral", - age: 31 - }); - \ No newline at end of file diff --git a/tests/baselines/reference/templateLiteralIntersection4.types b/tests/baselines/reference/templateLiteralIntersection4.types index 9524ed31bf9a5..f43c2b94b7ede 100644 --- a/tests/baselines/reference/templateLiteralIntersection4.types +++ b/tests/baselines/reference/templateLiteralIntersection4.types @@ -23,8 +23,8 @@ declare function createStore(store: Store): const { Provider, useUsername, useAge, useStore } = createStore({ >Provider : unknown ->useUsername : any ->useAge : any +>useUsername : StateHook +>useAge : StateHook >useStore : StateHook<{ username: string; age: number; }> >createStore({ username: "Aral", age: 31}) : StoreUtils<{ username: string; age: number; }> >createStore : (store: Store) => StoreUtils