✍ 공부/TypeScript

    [type-challenges] Tuple to Union

    0. 문제 튜플 값으로 유니온 타입을 생성하는 제네릭 TupleToUnion를 구현하세요. 1. 설명 /* _____________ 여기에 코드 입력 _____________ */ type TupleToUnion = T[number] /* _____________ 테스트 케이스 _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expect, ] 배열을 돌면서 유니온 타입 생성

    [type-challenges] Deep Readonly

    0. 문제 객체의 프로퍼티와 모든 하위 객체를 재귀적으로 읽기 전용으로 설정하는 제네릭 DeepReadonly를 구현하세요. 이 챌린지에서는 타입 파라미터 T를 객체 타입으로 제한하고 있습니다. 객체뿐만 아니라 배열, 함수, 클래스 등 가능한 다양한 형태의 타입 파라미터를 사용하도록 도전해 보세요. 1. 설명 /* _____________ 여기에 코드 입력 _____________ */ type DeepReadonly = {readonly [P in keyof T]: keyof T[P] extends never ? T[P] : DeepReadonly} type temp = DeepReadonly type t2 = DeepReadonly /* _____________ 테스트 케이스 _____________..

    [type-challenges] Parameters

    0. 문제 내장 제네릭 Parameters를 사용하지 않고 구현하세요 1. 설명 /* _____________ Your Code Here _____________ */ type MyParameters any> = T extends (...any: infer A)=> any ? A : A type A = MyParameters /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' const foo = (arg1: string, arg2: number): void => {} const bar = (arg1: boolean, arg2: { a: 'A' }): void => {}..

    [type-challenges] Unshift

    0. 문제 Array.unshift의 타입 버전을 구현하세요 1. 설명 /* _____________ Your Code Here _____________ */ type Unshift = [U,...T] /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expect, Expect, ] [type-challenges] push와 비슷하다 unshift시킬 U를 앞에 두고 arr type을 개행으로 풀어준다

    [type-challenges] Push

    0. 문제 Array.push의 제네릭 버전을 구현하세요 1. 설명 /* _____________ Your Code Here _____________ */ type Push = [...T,U] /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expect, Expect, ] T를 개행으로 풀어 넣어주고 뒤에 U를 이어넣으면 된다

    [type-challenges] Concat

    0. 문제 Javascript의 Array.concat 함수를 타입 시스템에서 구현하세요. 1. 설명 /* _____________ Your Code Here _____________ */ type Concat = [...T , ...U] /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' const tuple = [1] as const type cases = [ Expect, Expect, Expect, Expect, Expect, ] // @ts-expect-error type error = Concat type Concat = [...T , ...U] 이와같이 T와..

    [type-challenges] If

    0. 문제 조건 C, 참일 때의 반환타입 T, 거짓일 때 반환타입 F를 받는 타입 IF를 구현하기. C는 true 또는 false, T,F는 아무 타입 1. 설명 /* _____________ Your Code Here _____________ */ type If = C extends true ? T : F /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expect, ] // @ts-expect-error type error = If C는 true or false여야 하니까 C는 boolean을 extends하는 것. 만약 ..

    [type-challenges] Awaited

    0. 문제 Promise와 같은 타입에 감싸진 타입이 있을 때, 안에 감싸진 타입이 무엇인지 찾아보자 1. 설명 /* _____________ Your Code Here _____________ */ type MyAwaited = T extends Promise ? P extends Promise ? MyAwaited : P : T extends { then: (onfulfilled: (arg: infer K) => any) => any } ? K : error type MyAwaited2 = Awaited /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type X..