Fix crash in union subtype reduction involving template literal and string mapping types (#52699)

This commit is contained in:
Anders Hejlsberg 2023-02-09 15:04:57 -08:00 committed by GitHub
parent 6c9792aa87
commit bd905d4936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 1 deletions

View File

@ -16124,7 +16124,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function removeStringLiteralsMatchedByTemplateLiterals(types: Type[]) {
const templates = filter(types, isPatternLiteralType) as TemplateLiteralType[];
const templates = filter(types, t => !!(t.flags & TypeFlags.TemplateLiteral) && isPatternLiteralType(t)) as TemplateLiteralType[];
if (templates.length) {
let i = types.length;
while (i > 0) {

View File

@ -217,4 +217,8 @@ tests/cases/conformance/types/literal/templateLiteralTypes3.ts(141,9): error TS2
spread(`1.${u}.3`, `1.${u}.4`);
spread(u1, u2);
}
// Repro from #52685
type Boom = 'abc' | 'def' | `a${string}` | Lowercase<string>;

View File

@ -189,6 +189,10 @@ function ft1<T extends string>(t: T, u: Uppercase<T>, u1: Uppercase<`1.${T}.3`>,
spread(`1.${u}.3`, `1.${u}.4`);
spread(u1, u2);
}
// Repro from #52685
type Boom = 'abc' | 'def' | `a${string}` | Lowercase<string>;
//// [templateLiteralTypes3.js]
@ -356,3 +360,4 @@ type DotString = `${string}.${string}.${string}`;
declare function noSpread<P extends DotString>(args: P[]): P;
declare function spread<P extends DotString>(...args: P[]): P;
declare function ft1<T extends string>(t: T, u: Uppercase<T>, u1: Uppercase<`1.${T}.3`>, u2: Uppercase<`1.${T}.4`>): void;
type Boom = 'abc' | 'def' | `a${string}` | Lowercase<string>;

View File

@ -580,3 +580,9 @@ function ft1<T extends string>(t: T, u: Uppercase<T>, u1: Uppercase<`1.${T}.3`>,
>u2 : Symbol(u2, Decl(templateLiteralTypes3.ts, 185, 80))
}
// Repro from #52685
type Boom = 'abc' | 'def' | `a${string}` | Lowercase<string>;
>Boom : Symbol(Boom, Decl(templateLiteralTypes3.ts, 189, 1))
>Lowercase : Symbol(Lowercase, Decl(lib.es5.d.ts, --, --))

View File

@ -594,3 +594,8 @@ function ft1<T extends string>(t: T, u: Uppercase<T>, u1: Uppercase<`1.${T}.3`>,
>u2 : `1.${Uppercase<T>}.4`
}
// Repro from #52685
type Boom = 'abc' | 'def' | `a${string}` | Lowercase<string>;
>Boom : `a${string}` | Lowercase<string> | "def"

View File

@ -191,3 +191,7 @@ function ft1<T extends string>(t: T, u: Uppercase<T>, u1: Uppercase<`1.${T}.3`>,
spread(`1.${u}.3`, `1.${u}.4`);
spread(u1, u2);
}
// Repro from #52685
type Boom = 'abc' | 'def' | `a${string}` | Lowercase<string>;