TypeScript: how to declare array of fixed size for type checking at Compile Time

前端 未结 3 1317
生来不讨喜
生来不讨喜 2021-01-17 10:19

Update: These checks are meant for compile time, not at runtime. In my example, the failed cases are all caught at compile

3条回答
  •  悲&欢浪女
    2021-01-17 10:57

    From Typescript: Can I define an n-length tuple type?, programmatically, with dynamic length:

    type Tuple = [TItem, ...TItem[]] & { length: TLength };
    
    type Tuple9 = Tuple;
    

提交回复
热议问题