-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cherry pick "No
this
type arguments in base constraints (#54536)" t…
…o release-5.1 (#54814) Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
- Loading branch information
1 parent
e7f1caf
commit ac5884a
Showing
6 changed files
with
188 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
=== tests/cases/compiler/largeTupleTypes.ts === | ||
// Repro from #54491 | ||
|
||
type UnshiftTuple<T extends [...any[]]> = T extends [T[0], ...infer Tail] ? Tail : never; | ||
>UnshiftTuple : Symbol(UnshiftTuple, Decl(largeTupleTypes.ts, 0, 0)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 2, 18)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 2, 18)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 2, 18)) | ||
>Tail : Symbol(Tail, Decl(largeTupleTypes.ts, 2, 67)) | ||
>Tail : Symbol(Tail, Decl(largeTupleTypes.ts, 2, 67)) | ||
|
||
type ExpandSmallerTuples<T extends [...any[]]> = T extends [T[0], ...infer Tail] ? T | ExpandSmallerTuples<Tail> : []; | ||
>ExpandSmallerTuples : Symbol(ExpandSmallerTuples, Decl(largeTupleTypes.ts, 2, 89)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 3, 25)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 3, 25)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 3, 25)) | ||
>Tail : Symbol(Tail, Decl(largeTupleTypes.ts, 3, 74)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 3, 25)) | ||
>ExpandSmallerTuples : Symbol(ExpandSmallerTuples, Decl(largeTupleTypes.ts, 2, 89)) | ||
>Tail : Symbol(Tail, Decl(largeTupleTypes.ts, 3, 74)) | ||
|
||
type Shift<A extends Array<any>> = ((...args: A) => void) extends (...args: [A[0], ...infer R]) => void ? R : never; | ||
>Shift : Symbol(Shift, Decl(largeTupleTypes.ts, 3, 118)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 4, 11)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>args : Symbol(args, Decl(largeTupleTypes.ts, 4, 37)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 4, 11)) | ||
>args : Symbol(args, Decl(largeTupleTypes.ts, 4, 67)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 4, 11)) | ||
>R : Symbol(R, Decl(largeTupleTypes.ts, 4, 91)) | ||
>R : Symbol(R, Decl(largeTupleTypes.ts, 4, 91)) | ||
|
||
type GrowExpRev<A extends Array<any>, N extends number, P extends Array<Array<any>>> = A['length'] extends N ? A : GrowExpRev<[...A, ...P[0]][N] extends undefined ? [...A, ...P[0]] : A, N, Shift<P>>; | ||
>GrowExpRev : Symbol(GrowExpRev, Decl(largeTupleTypes.ts, 4, 116)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 5, 16)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 5, 37)) | ||
>P : Symbol(P, Decl(largeTupleTypes.ts, 5, 55)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 5, 16)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 5, 37)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 5, 16)) | ||
>GrowExpRev : Symbol(GrowExpRev, Decl(largeTupleTypes.ts, 4, 116)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 5, 16)) | ||
>P : Symbol(P, Decl(largeTupleTypes.ts, 5, 55)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 5, 37)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 5, 16)) | ||
>P : Symbol(P, Decl(largeTupleTypes.ts, 5, 55)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 5, 16)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 5, 37)) | ||
>Shift : Symbol(Shift, Decl(largeTupleTypes.ts, 3, 118)) | ||
>P : Symbol(P, Decl(largeTupleTypes.ts, 5, 55)) | ||
|
||
type GrowExp<A extends Array<any>, N extends number, P extends Array<Array<any>>> = [...A, ...A][N] extends undefined ? GrowExp<[...A, ...A], N, [A, ...P]> : GrowExpRev<A, N, P>; | ||
>GrowExp : Symbol(GrowExp, Decl(largeTupleTypes.ts, 5, 199)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 6, 13)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 6, 34)) | ||
>P : Symbol(P, Decl(largeTupleTypes.ts, 6, 52)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 6, 13)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 6, 13)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 6, 34)) | ||
>GrowExp : Symbol(GrowExp, Decl(largeTupleTypes.ts, 5, 199)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 6, 13)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 6, 13)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 6, 34)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 6, 13)) | ||
>P : Symbol(P, Decl(largeTupleTypes.ts, 6, 52)) | ||
>GrowExpRev : Symbol(GrowExpRev, Decl(largeTupleTypes.ts, 4, 116)) | ||
>A : Symbol(A, Decl(largeTupleTypes.ts, 6, 13)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 6, 34)) | ||
>P : Symbol(P, Decl(largeTupleTypes.ts, 6, 52)) | ||
|
||
type Tuple<T, N extends number> = number extends N ? Array<T> : N extends 0 ? [] : N extends 1 ? [T] : GrowExp<[T], N, [[]]>; | ||
>Tuple : Symbol(Tuple, Decl(largeTupleTypes.ts, 6, 178)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 7, 11)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 7, 13)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 7, 13)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 7, 11)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 7, 13)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 7, 13)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 7, 11)) | ||
>GrowExp : Symbol(GrowExp, Decl(largeTupleTypes.ts, 5, 199)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 7, 11)) | ||
>N : Symbol(N, Decl(largeTupleTypes.ts, 7, 13)) | ||
|
||
declare class ArrayValidator<T extends unknown[], I = T[number]> { | ||
>ArrayValidator : Symbol(ArrayValidator, Decl(largeTupleTypes.ts, 7, 125)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 9, 29)) | ||
>I : Symbol(I, Decl(largeTupleTypes.ts, 9, 49)) | ||
>T : Symbol(T, Decl(largeTupleTypes.ts, 9, 29)) | ||
|
||
lengthRange<S extends number, E extends number>(start: S, endBefore: E): ArrayValidator<Exclude<ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, E>]>>, ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, S>]>>>>; | ||
>lengthRange : Symbol(ArrayValidator.lengthRange, Decl(largeTupleTypes.ts, 9, 66)) | ||
>S : Symbol(S, Decl(largeTupleTypes.ts, 10, 16)) | ||
>E : Symbol(E, Decl(largeTupleTypes.ts, 10, 33)) | ||
>start : Symbol(start, Decl(largeTupleTypes.ts, 10, 52)) | ||
>S : Symbol(S, Decl(largeTupleTypes.ts, 10, 16)) | ||
>endBefore : Symbol(endBefore, Decl(largeTupleTypes.ts, 10, 61)) | ||
>E : Symbol(E, Decl(largeTupleTypes.ts, 10, 33)) | ||
>ArrayValidator : Symbol(ArrayValidator, Decl(largeTupleTypes.ts, 7, 125)) | ||
>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) | ||
>ExpandSmallerTuples : Symbol(ExpandSmallerTuples, Decl(largeTupleTypes.ts, 2, 89)) | ||
>UnshiftTuple : Symbol(UnshiftTuple, Decl(largeTupleTypes.ts, 0, 0)) | ||
>Tuple : Symbol(Tuple, Decl(largeTupleTypes.ts, 6, 178)) | ||
>I : Symbol(I, Decl(largeTupleTypes.ts, 9, 49)) | ||
>E : Symbol(E, Decl(largeTupleTypes.ts, 10, 33)) | ||
>ExpandSmallerTuples : Symbol(ExpandSmallerTuples, Decl(largeTupleTypes.ts, 2, 89)) | ||
>UnshiftTuple : Symbol(UnshiftTuple, Decl(largeTupleTypes.ts, 0, 0)) | ||
>Tuple : Symbol(Tuple, Decl(largeTupleTypes.ts, 6, 178)) | ||
>I : Symbol(I, Decl(largeTupleTypes.ts, 9, 49)) | ||
>S : Symbol(S, Decl(largeTupleTypes.ts, 10, 16)) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=== tests/cases/compiler/largeTupleTypes.ts === | ||
// Repro from #54491 | ||
|
||
type UnshiftTuple<T extends [...any[]]> = T extends [T[0], ...infer Tail] ? Tail : never; | ||
>UnshiftTuple : UnshiftTuple<T> | ||
|
||
type ExpandSmallerTuples<T extends [...any[]]> = T extends [T[0], ...infer Tail] ? T | ExpandSmallerTuples<Tail> : []; | ||
>ExpandSmallerTuples : ExpandSmallerTuples<T> | ||
|
||
type Shift<A extends Array<any>> = ((...args: A) => void) extends (...args: [A[0], ...infer R]) => void ? R : never; | ||
>Shift : Shift<A> | ||
>args : A | ||
>args : [A[0], ...R] | ||
|
||
type GrowExpRev<A extends Array<any>, N extends number, P extends Array<Array<any>>> = A['length'] extends N ? A : GrowExpRev<[...A, ...P[0]][N] extends undefined ? [...A, ...P[0]] : A, N, Shift<P>>; | ||
>GrowExpRev : GrowExpRev<A, N, P> | ||
|
||
type GrowExp<A extends Array<any>, N extends number, P extends Array<Array<any>>> = [...A, ...A][N] extends undefined ? GrowExp<[...A, ...A], N, [A, ...P]> : GrowExpRev<A, N, P>; | ||
>GrowExp : GrowExp<A, N, P> | ||
|
||
type Tuple<T, N extends number> = number extends N ? Array<T> : N extends 0 ? [] : N extends 1 ? [T] : GrowExp<[T], N, [[]]>; | ||
>Tuple : Tuple<T, N> | ||
|
||
declare class ArrayValidator<T extends unknown[], I = T[number]> { | ||
>ArrayValidator : ArrayValidator<T, I> | ||
|
||
lengthRange<S extends number, E extends number>(start: S, endBefore: E): ArrayValidator<Exclude<ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, E>]>>, ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, S>]>>>>; | ||
>lengthRange : <S extends number, E extends number>(start: S, endBefore: E) => ArrayValidator<Exclude<ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, E>]>>, ExpandSmallerTuples<UnshiftTuple<[...Tuple<I, S>]>>>> | ||
>start : S | ||
>endBefore : E | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.