Normalize variadic tuples with reduced never element type to never

This commit is contained in:
Mateusz Burzyński 2024-09-05 12:42:07 +02:00
Родитель a709f9899c
Коммит f80d34bf2e
6 изменённых файлов: 67 добавлений и 1 удалений

Просмотреть файл

@ -17455,6 +17455,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// Spread variadic elements with tuple types into the resulting tuple.
forEach(elements, (t, n) => addElement(t, type.target.elementFlags[n], type.target.labeledElementDeclarations?.[n]));
}
else if (getReducedApparentType(type).flags & TypeFlags.Never) {
return neverType;
}
else {
// Treat everything else as an array type and create a rest element.
addElement(isArrayLikeType(type) && getIndexTypeOfType(type, numberType) || errorType, ElementFlags.Rest, target.labeledElementDeclarations?.[i]);

Просмотреть файл

@ -542,4 +542,10 @@ variadicTuples1.ts(411,7): error TS2322: Type '[boolean, false]' is not assignab
type ToStringLength2<T extends any[]> = `${[...T]['length']}`;
type AnyArr = [...any];
type NeverSpread1 = [...never];
type IdentitySpread<T extends readonly unknown[]> = [...T];
type NeverSpread2 = IdentitySpread<never>;
type ReducedNeverSpread1 = IdentitySpread<[] & [string]>;
type ReducedNeverSpread2 = IdentitySpread<[string | boolean, boolean, ...number[]] & ['foo', string, 44]>;

Просмотреть файл

@ -423,6 +423,12 @@ type ToStringLength1<T extends any[]> = `${T['length']}`;
type ToStringLength2<T extends any[]> = `${[...T]['length']}`;
type AnyArr = [...any];
type NeverSpread1 = [...never];
type IdentitySpread<T extends readonly unknown[]> = [...T];
type NeverSpread2 = IdentitySpread<never>;
type ReducedNeverSpread1 = IdentitySpread<[] & [string]>;
type ReducedNeverSpread2 = IdentitySpread<[string | boolean, boolean, ...number[]] & ['foo', string, 44]>;
//// [variadicTuples1.js]
@ -833,6 +839,11 @@ type U3 = [...[string, number], boolean];
type ToStringLength1<T extends any[]> = `${T['length']}`;
type ToStringLength2<T extends any[]> = `${[...T]['length']}`;
type AnyArr = [...any];
type NeverSpread1 = [...never];
type IdentitySpread<T extends readonly unknown[]> = [...T];
type NeverSpread2 = IdentitySpread<never>;
type ReducedNeverSpread1 = IdentitySpread<[] & [string]>;
type ReducedNeverSpread2 = IdentitySpread<[string | boolean, boolean, ...number[]] & ['foo', string, 44]>;
!!!! File variadicTuples1.d.ts differs from original emit in noCheck emit

Просмотреть файл

@ -1419,3 +1419,23 @@ type ToStringLength2<T extends any[]> = `${[...T]['length']}`;
type AnyArr = [...any];
>AnyArr : Symbol(AnyArr, Decl(variadicTuples1.ts, 419, 62))
type NeverSpread1 = [...never];
>NeverSpread1 : Symbol(NeverSpread1, Decl(variadicTuples1.ts, 421, 23))
type IdentitySpread<T extends readonly unknown[]> = [...T];
>IdentitySpread : Symbol(IdentitySpread, Decl(variadicTuples1.ts, 423, 31))
>T : Symbol(T, Decl(variadicTuples1.ts, 424, 20))
>T : Symbol(T, Decl(variadicTuples1.ts, 424, 20))
type NeverSpread2 = IdentitySpread<never>;
>NeverSpread2 : Symbol(NeverSpread2, Decl(variadicTuples1.ts, 424, 59))
>IdentitySpread : Symbol(IdentitySpread, Decl(variadicTuples1.ts, 423, 31))
type ReducedNeverSpread1 = IdentitySpread<[] & [string]>;
>ReducedNeverSpread1 : Symbol(ReducedNeverSpread1, Decl(variadicTuples1.ts, 425, 42))
>IdentitySpread : Symbol(IdentitySpread, Decl(variadicTuples1.ts, 423, 31))
type ReducedNeverSpread2 = IdentitySpread<[string | boolean, boolean, ...number[]] & ['foo', string, 44]>;
>ReducedNeverSpread2 : Symbol(ReducedNeverSpread2, Decl(variadicTuples1.ts, 426, 57))
>IdentitySpread : Symbol(IdentitySpread, Decl(variadicTuples1.ts, 423, 31))

Просмотреть файл

@ -1,7 +1,7 @@
//// [tests/cases/conformance/types/tuple/variadicTuples1.ts] ////
=== Performance Stats ===
Type Count: 1,000
Type Count: 1,000 -> 2,500
Instantiation count: 2,500
=== variadicTuples1.ts ===
@ -2304,3 +2304,23 @@ type AnyArr = [...any];
>AnyArr : any[]
> : ^^^^^
type NeverSpread1 = [...never];
>NeverSpread1 : never
> : ^^^^^
type IdentitySpread<T extends readonly unknown[]> = [...T];
>IdentitySpread : [...T]
> : ^^^^^^
type NeverSpread2 = IdentitySpread<never>;
>NeverSpread2 : never
> : ^^^^^
type ReducedNeverSpread1 = IdentitySpread<[] & [string]>;
>ReducedNeverSpread1 : never
> : ^^^^^
type ReducedNeverSpread2 = IdentitySpread<[string | boolean, boolean, ...number[]] & ['foo', string, 44]>;
>ReducedNeverSpread2 : never
> : ^^^^^

Просмотреть файл

@ -423,3 +423,9 @@ type ToStringLength1<T extends any[]> = `${T['length']}`;
type ToStringLength2<T extends any[]> = `${[...T]['length']}`;
type AnyArr = [...any];
type NeverSpread1 = [...never];
type IdentitySpread<T extends readonly unknown[]> = [...T];
type NeverSpread2 = IdentitySpread<never>;
type ReducedNeverSpread1 = IdentitySpread<[] & [string]>;
type ReducedNeverSpread2 = IdentitySpread<[string | boolean, boolean, ...number[]] & ['foo', string, 44]>;