✍ 공부/TypeScript

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

    [type-challenges] Pick

    0. 문제 Pick를 쓰지않고 타입 제어하기 type MyPick = { [key in K] :T[key] } /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expect, // @ts-expect-error MyPick, ] interface Todo { title: string description: string completed: boolean } interface Expected1 { title: string } interface Expected2 { title: string completed: boolean } /* ..

    [ 러닝 타입스크립트 ] 챕터 7. 인터페이스

    타입스크립트 스터디에서 정리한 내용! interface는 자주 사용해서 간단하겠거니~ 생각하고 읽기 시작했는데 내 생각보다 나는 더 모르고 타입의 세계는 넓다는 것을 깨달았다. 챕터7. 인터페이스 러닝 타입스크립트 131p 핵심 우리가 직접 만들 수 있는데 왜 지루한 내장 티입 형태만 사용하나요? 인터페이스? : 연관된 이름으로 객체 형태를 설명하는 또 다른 방법. 특징 별칭으로 된 객체 타입과 유사 더 읽기 쉬운 오류 메시지 더 빠른 컴파일러 성능 클래스와의 더 나은 상호 운용성 을 위해 사용된다 📚 07.1 타입 별칭 vs. 인터페이스 // 타입 별칭 type Poet = { born: number; name: string; } // 인터페이스 interface Poet { born: number; ..