Open lxxmnmn opened 1 month ago
배열(튜플)을 받아 길이를 반환하는 제네릭 Length<T>를 구현하세요.
Length<T>
/* _____________ Your Code Here _____________ */ type Length<T extends readonly any[]> = T['length'];
/* _____________ Test Cases _____________ */ 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'>, ]
T['length']는 배열 타입 T의 길이를 타입으로 나타냄
T['length']
T
type MyTuple = [number, string, boolean]; type Length = MyTuple['length']; // 3
Length of Tuple
배열(튜플)을 받아 길이를 반환하는 제네릭
Length<T>
를 구현하세요.