튜플의 length 타입을 만들어라.
/*
18 - Length of Tuple
-------
by sinoon (@sinoon) #easy #tuple
### Question
For given a tuple, you need create a generic `Length`, pick the length of the tuple
For example
```ts
type tesla = ['tesla', 'model 3', 'model X', 'model Y'] as const
type spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT'] as const
type teslaLength = Length<typeof tesla> // expected 4
type spaceXLength = Length<typeof spaceX> // expected 5
View on GitHub: https://tsch.js.org/18 */
/* _____________ Your Code Here _____________ */
type Length<T extends any> = any
/* _____________ Test Cases _____________ */ import { Equal, Expect } from '@type-challenges/utils'
const tesla = ['tesla', 'model 3', 'model X', 'model Y'] as const const spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT'] as const
type cases = [ Expect<Equal<Length<typeof tesla>, 4>>, Expect<Equal<Length<typeof spaceX>, 5>>, ]
/* _____________ Further Steps _____________ / /
Share your solutions: https://tsch.js.org/18/answer View solutions: https://tsch.js.org/18/solutions More Challenges: https://tsch.js.org */
첨에 `T extends any` 를 튜플로 좁혀 준 다음 `length`로 뽑았다.
```tsx
type Length<T extends readonly any[]> = T['length']
다른 답
type Length<T extends readonly unknown[]> = T['length']
unknown에 대해 궁금해 진다.