Length of Tuple
提出詳細
type Length<T extends readonly any[]> = T extends readonly [any, any, any, any] ? 4 : T extends readonly [any, any, any, any, any] ? 5 : never
提出日時 | 2023-08-26 05:43:55 |
---|---|
問題 | Length of Tuple |
ユーザー | snaka |
ステータス | Accepted |
import type { 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>>, // @ts-expect-error Length<5>, // @ts-expect-error Length<'hello world'>, ]