Remove incorrect handling of intersections in getStringMappingType (#53383)

This commit is contained in:
Jake Bailey 2023-03-20 13:44:25 -07:00 committed by GitHub
parent 8814f6da48
commit 3ba3ace236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 141 additions and 3 deletions

View File

@ -17118,7 +17118,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<T>> === Mapping<T>

View File

@ -29,12 +29,12 @@ options1[`foo/${path}`] = false;
// Lowercase<`foo/${Path}`> => `foo/${Lowercase<Path>}`
declare const lowercasePath: Lowercase<`foo/${Path}`>;
>lowercasePath : `foo/${Lowercase<string> & { _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<string> & { _pathBrand: any; }}`
>lowercasePath : `foo/${Lowercase<`${Path}`>}`
>false : false

View File

@ -0,0 +1,24 @@
//// [templateLiteralIntersection4.ts]
type StateHook<S> = () => [S, unknown];
type StoreUtils<Store extends { [K: string]: any }> = Omit<{
[K in keyof Store as `use${Capitalize<string & K>}`]: StateHook<Store[K]>
}, 'useStore'> & {
Provider: unknown,
useStore: StateHook<Store>
};
declare function createStore<Store extends { [K: string]: any }>(store: Store): StoreUtils<Store>;
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;

View File

@ -0,0 +1,56 @@
=== tests/cases/compiler/templateLiteralIntersection4.ts ===
type StateHook<S> = () => [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<Store extends { [K: string]: any }> = 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<string & K>}`]: StateHook<Store[K]>
>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<Store>
>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 extends { [K: string]: any }>(store: Store): StoreUtils<Store>;
>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))
});

View File

@ -0,0 +1,42 @@
=== tests/cases/compiler/templateLiteralIntersection4.ts ===
type StateHook<S> = () => [S, unknown];
>StateHook : StateHook<S>
type StoreUtils<Store extends { [K: string]: any }> = Omit<{
>StoreUtils : StoreUtils<Store>
>K : string
[K in keyof Store as `use${Capitalize<string & K>}`]: StateHook<Store[K]>
}, 'useStore'> & {
Provider: unknown,
>Provider : unknown
useStore: StateHook<Store>
>useStore : StateHook<Store>
};
declare function createStore<Store extends { [K: string]: any }>(store: Store): StoreUtils<Store>;
>createStore : <Store extends { [K: string]: any; }>(store: Store) => StoreUtils<Store>
>K : string
>store : Store
const { Provider, useUsername, useAge, useStore } = createStore({
>Provider : unknown
>useUsername : StateHook<string>
>useAge : StateHook<number>
>useStore : StateHook<{ username: string; age: number; }>
>createStore({ username: "Aral", age: 31}) : StoreUtils<{ username: string; age: number; }>
>createStore : <Store extends { [K: string]: any; }>(store: Store) => StoreUtils<Store>
>{ username: "Aral", age: 31} : { username: string; age: number; }
username: "Aral",
>username : string
>"Aral" : "Aral"
age: 31
>age : number
>31 : 31
});

View File

@ -0,0 +1,17 @@
// @strict: true
type StateHook<S> = () => [S, unknown];
type StoreUtils<Store extends { [K: string]: any }> = Omit<{
[K in keyof Store as `use${Capitalize<string & K>}`]: StateHook<Store[K]>
}, 'useStore'> & {
Provider: unknown,
useStore: StateHook<Store>
};
declare function createStore<Store extends { [K: string]: any }>(store: Store): StoreUtils<Store>;
const { Provider, useUsername, useAge, useStore } = createStore({
username: "Aral",
age: 31
});