전체 글

전체 글

    [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..

    [type-challenges] Exclude

    0. 문제 T에서 U에 할당할 수 있는 타입을 제외하는 제네릭을, Exclude를 사용하지 않고 구현하세요 1. 설명 type MyExclude = T extends U ? never : T /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expect, Expect>, ] type MyExclude = T extends U ? never : T T가 U를 extends하면 => T는 'a'. 'b'. 'c' 가 차례대로 들어오고 있다 이 때 'a'를 만나게 되면(U == 'a'일 때) never로 넘겨주고 나머지는 그냥 다시 ..

    [type-challenges] Length of Tuple

    0. 문제 배열(튜플)을 받아 길이를 반환하는 제네릭 Length를 구현하세요. 1. 설명 /* _____________ Your Code Here _____________ */ type Length = 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 ..

    [type-challenges] First of Array

    0. 문제 배열(튜플) T를 받아 첫 원소의 타입을 반환하는 제네릭 First를 구현하세요. 1. 설명 /* _____________ Your Code Here _____________ */ type First = T extends [] ? never :T[0] type Mytype = First 123, { a: string }]> type Mytype2 = First /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expect 123>>, Expect, Expect, ] type errors = [ // @ts-expect..

    [type-challenges] Tuple to Object

    0. 문제 배열이 주어지면, 이를 객체로 변경하세요(key와 value는 제공된 배열에 존재해야 합니다) 1. 설명 /* _____________ Your Code Here _____________ */ type TupleToObject = {[P in T[number]]: P} type MyType = TupleToObject // 확인용 /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const const tupleNumber = [1, 2, 3, 4] as..

    [type-challenges] Readonly

    0. 문제 Readonly 쓰지 않고 readonly 만들기 1. 설명 /* _____________ Your Code Here _____________ */ type MyReadonly = {readonly [key in keyof T]: T[key]} /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, ] interface Todo1 { title: string description: string completed: boolean meta: { author: string } } MyReadonly는 T를 받아서 [key in ..