How to get type of array items?

后端 未结 5 1049
有刺的猬
有刺的猬 2020-11-29 10:03

If I have a type type foo = Array<{ name: string; test: number; }>, would it be possible to get the type of the values within the array, in this case, the

5条回答
  •  情书的邮戳
    2020-11-29 10:34

    If you're looking to how to extract { name: string; test: number; } type, you can simply create alias to "item at index":

    type Foo = Array<{ name: string; test: number; }>;
    type FooItem = Foo[0];
    

    or

    type FooItem = Foo[number];
    

提交回复
热议问题