Length of Tuple - easy - [Type Challenge]

강성훈·2023년 1월 23일
1

type-challenges

목록 보기
5/20
post-thumbnail

by sinoon @sinoon

배열(튜플)을 받아 길이를 반환하는 제네릭 Length<T>

type tesla = ['tesla', 'model 3', 'model X', 'model Y']
type spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT']

type teslaLength = Length<tesla>  // expected 4
type spaceXLength = Length<spaceX> // expected 5

타입 변수 한 개를 입력받는다. 이는 배열이다.

type Length<T extends any[]> = ??

그리고 그 T의 길이를 구하면 된다.

type Length<T extends any[]> = T["length"];
profile
고등학생 주니어 개발자

0개의 댓글