Construct a tuple with a given length.
For example
type result = ConstructTuple<2> // expect to be [unknown, unkonwn]
/* _____________ Your Code Here _____________ */
type ConstructTuple<L extends number, ACC extends unknown[] = []> = L extends 0
? []
: ACC['length'] extends L
? ACC
: ConstructTuple<L, [...ACC, unknown]>;
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<ConstructTuple<0>, []>>,
Expect<Equal<ConstructTuple<2>, [unknown, unknown]>>,
Expect<Equal<ConstructTuple<999>['length'], 999>>,
// @ts-expect-error
Expect<Equal<ConstructTuple<1000>['length'], 1000>>,
]
标签:Typescript,ConstructTuple,_____________,Construct,length,Medium,Expect,80,type From: https://www.cnblogs.com/Answer1215/p/16841593.html