mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Propagate wildcard types in template literal type construction (#40875)
* Propagate wildcard types in template literal type construction * Add regression test * Accept new baselines
This commit is contained in:
parent
b93da6291a
commit
950dad9c29
@ -13565,6 +13565,9 @@ namespace ts {
|
||||
mapType(types[unionIndex], t => getTemplateLiteralType(texts, replaceElement(types, unionIndex, t))) :
|
||||
errorType;
|
||||
}
|
||||
if (contains(types, wildcardType)) {
|
||||
return wildcardType;
|
||||
}
|
||||
const newTypes: Type[] = [];
|
||||
const newTexts: string[] = [];
|
||||
let text = texts[0];
|
||||
|
||||
@ -232,4 +232,13 @@ tests/cases/conformance/types/literal/templateLiteralTypes1.ts(205,16): error TS
|
||||
type T100000 = [...TDigits, ...TDigits, ...TDigits, ...TDigits, ...TDigits]; // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2590: Expression produces a union type that is too complex to represent.
|
||||
|
||||
// Repro from #40863
|
||||
|
||||
type IsNegative<T extends number> = `${T}` extends `-${string}` ? true : false;
|
||||
|
||||
type AA<T extends number, Q extends number> =
|
||||
[true, true] extends [IsNegative<T>, IsNegative<Q>] ? 'Every thing is ok!' : ['strange', IsNegative<T>, IsNegative<Q>];
|
||||
|
||||
type BB = AA<-2, -2>;
|
||||
|
||||
@ -204,6 +204,15 @@ type D100000 = `${Digits}${Digits}${Digits}${Digits}${Digits}`; // Error
|
||||
type TDigits = [0] | [1] | [2] | [3] | [4] | [5] | [6] | [7] | [8] | [9];
|
||||
|
||||
type T100000 = [...TDigits, ...TDigits, ...TDigits, ...TDigits, ...TDigits]; // Error
|
||||
|
||||
// Repro from #40863
|
||||
|
||||
type IsNegative<T extends number> = `${T}` extends `-${string}` ? true : false;
|
||||
|
||||
type AA<T extends number, Q extends number> =
|
||||
[true, true] extends [IsNegative<T>, IsNegative<Q>] ? 'Every thing is ok!' : ['strange', IsNegative<T>, IsNegative<Q>];
|
||||
|
||||
type BB = AA<-2, -2>;
|
||||
|
||||
|
||||
//// [templateLiteralTypes1.js]
|
||||
@ -453,3 +462,9 @@ declare type Digits = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
||||
declare type D100000 = `${Digits}${Digits}${Digits}${Digits}${Digits}`;
|
||||
declare type TDigits = [0] | [1] | [2] | [3] | [4] | [5] | [6] | [7] | [8] | [9];
|
||||
declare type T100000 = [...TDigits, ...TDigits, ...TDigits, ...TDigits, ...TDigits];
|
||||
declare type IsNegative<T extends number> = `${T}` extends `-${string}` ? true : false;
|
||||
declare type AA<T extends number, Q extends number> = [
|
||||
true,
|
||||
true
|
||||
] extends [IsNegative<T>, IsNegative<Q>] ? 'Every thing is ok!' : ['strange', IsNegative<T>, IsNegative<Q>];
|
||||
declare type BB = AA<-2, -2>;
|
||||
|
||||
@ -843,3 +843,29 @@ type T100000 = [...TDigits, ...TDigits, ...TDigits, ...TDigits, ...TDigits]; //
|
||||
>TDigits : Symbol(TDigits, Decl(templateLiteralTypes1.ts, 200, 63))
|
||||
>TDigits : Symbol(TDigits, Decl(templateLiteralTypes1.ts, 200, 63))
|
||||
|
||||
// Repro from #40863
|
||||
|
||||
type IsNegative<T extends number> = `${T}` extends `-${string}` ? true : false;
|
||||
>IsNegative : Symbol(IsNegative, Decl(templateLiteralTypes1.ts, 204, 76))
|
||||
>T : Symbol(T, Decl(templateLiteralTypes1.ts, 208, 16))
|
||||
>T : Symbol(T, Decl(templateLiteralTypes1.ts, 208, 16))
|
||||
|
||||
type AA<T extends number, Q extends number> =
|
||||
>AA : Symbol(AA, Decl(templateLiteralTypes1.ts, 208, 79))
|
||||
>T : Symbol(T, Decl(templateLiteralTypes1.ts, 210, 8))
|
||||
>Q : Symbol(Q, Decl(templateLiteralTypes1.ts, 210, 25))
|
||||
|
||||
[true, true] extends [IsNegative<T>, IsNegative<Q>] ? 'Every thing is ok!' : ['strange', IsNegative<T>, IsNegative<Q>];
|
||||
>IsNegative : Symbol(IsNegative, Decl(templateLiteralTypes1.ts, 204, 76))
|
||||
>T : Symbol(T, Decl(templateLiteralTypes1.ts, 210, 8))
|
||||
>IsNegative : Symbol(IsNegative, Decl(templateLiteralTypes1.ts, 204, 76))
|
||||
>Q : Symbol(Q, Decl(templateLiteralTypes1.ts, 210, 25))
|
||||
>IsNegative : Symbol(IsNegative, Decl(templateLiteralTypes1.ts, 204, 76))
|
||||
>T : Symbol(T, Decl(templateLiteralTypes1.ts, 210, 8))
|
||||
>IsNegative : Symbol(IsNegative, Decl(templateLiteralTypes1.ts, 204, 76))
|
||||
>Q : Symbol(Q, Decl(templateLiteralTypes1.ts, 210, 25))
|
||||
|
||||
type BB = AA<-2, -2>;
|
||||
>BB : Symbol(BB, Decl(templateLiteralTypes1.ts, 211, 123))
|
||||
>AA : Symbol(AA, Decl(templateLiteralTypes1.ts, 208, 79))
|
||||
|
||||
|
||||
@ -515,3 +515,24 @@ type TDigits = [0] | [1] | [2] | [3] | [4] | [5] | [6] | [7] | [8] | [9];
|
||||
type T100000 = [...TDigits, ...TDigits, ...TDigits, ...TDigits, ...TDigits]; // Error
|
||||
>T100000 : any
|
||||
|
||||
// Repro from #40863
|
||||
|
||||
type IsNegative<T extends number> = `${T}` extends `-${string}` ? true : false;
|
||||
>IsNegative : IsNegative<T>
|
||||
>true : true
|
||||
>false : false
|
||||
|
||||
type AA<T extends number, Q extends number> =
|
||||
>AA : AA<T, Q>
|
||||
|
||||
[true, true] extends [IsNegative<T>, IsNegative<Q>] ? 'Every thing is ok!' : ['strange', IsNegative<T>, IsNegative<Q>];
|
||||
>true : true
|
||||
>true : true
|
||||
|
||||
type BB = AA<-2, -2>;
|
||||
>BB : "Every thing is ok!"
|
||||
>-2 : -2
|
||||
>2 : 2
|
||||
>-2 : -2
|
||||
>2 : 2
|
||||
|
||||
|
||||
@ -206,3 +206,12 @@ type D100000 = `${Digits}${Digits}${Digits}${Digits}${Digits}`; // Error
|
||||
type TDigits = [0] | [1] | [2] | [3] | [4] | [5] | [6] | [7] | [8] | [9];
|
||||
|
||||
type T100000 = [...TDigits, ...TDigits, ...TDigits, ...TDigits, ...TDigits]; // Error
|
||||
|
||||
// Repro from #40863
|
||||
|
||||
type IsNegative<T extends number> = `${T}` extends `-${string}` ? true : false;
|
||||
|
||||
type AA<T extends number, Q extends number> =
|
||||
[true, true] extends [IsNegative<T>, IsNegative<Q>] ? 'Every thing is ok!' : ['strange', IsNegative<T>, IsNegative<Q>];
|
||||
|
||||
type BB = AA<-2, -2>;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user