Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13552,6 +13552,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];
Expand Down
9 changes: 9 additions & 0 deletions tests/baselines/reference/templateLiteralTypes1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

15 changes: 15 additions & 0 deletions tests/baselines/reference/templateLiteralTypes1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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>;
26 changes: 26 additions & 0 deletions tests/baselines/reference/templateLiteralTypes1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))

21 changes: 21 additions & 0 deletions tests/baselines/reference/templateLiteralTypes1.types
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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>;