Push - easy - [Type Challenge]

강성훈·2023년 1월 25일
0

type-challenges

목록 보기
11/20
post-thumbnail

by jiangshan @jiangshanmeta

문제

Array.push의 제네릭 버전을 구현하세요.

type Result = Push<[1, 2], '3'> // [1, 2, '3']

솔루션

스페레드 연산자를 통해 배열을 복사하고, U를 뒤에 붙이면 Array.push랑 같은 역할을 하게 된다.

type Push<T extends any[], U> = [...T, U];
``
profile
고등학생 주니어 개발자

0개의 댓글