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.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..f43c2b94b7ede --- /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 : StateHook +>useAge : StateHook +>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 +});