React TypeScript 치트시트에서 TypeScript 생략을 이해하기 위한 전제 조건

소개



내가 배운 자원을 잊어버리지 않도록 자기 자신을 위한 메모.

의 React TypeScript Cheatsheet Props: Omit prop from a type 를 진행하면서 Omit 의 정의를 이해하는 데 문제가 있었습니다.

// this comes inbuilt with TS 3.5
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>

내 머리를 감쌀 수 없었으므로 Google에서 의 블로그 게시물을 찾았습니다.

블로그 읽기 순서



처음에는 거꾸로 읽었지만 다음 순서의 게시물이 의미가 있는 것 같습니다.

  • keyof and Lookup Types in TypeScript - keyofOmit에 사용된 Exclude에 대해 알아보기

  • Conditional Types in TypeScript - 이해하기 위해 Exclude

  •    type Exclude<T, U> = T extends U ? never : T
    


  • The Omit Helper Type in TypeScript - 마지막으로 Omit 구현 방법을 배우기 위해

  • 참고문헌



    Advaned utlity type documentsources
  • Omit<Type, Keys>

  • 정의: 유형에서 모든 속성을 선택한 다음 키를 제거하여 유형을 구성합니다.

  • 문서: https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys

  • 출처: https://github.com/microsoft/TypeScript/blob/master/lib/lib.es5.d.ts#L1504

  •    /**
        * Construct a type with the properties of T except for those in type K.
        */
       type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>
    

  • Pick<Type, Keys>

  • 정의: 유형에서 속성 키 세트를 선택하여 유형을 구성합니다.

  • 문서: https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys

  • 출처: https://github.com/microsoft/TypeScript/blob/master/lib/lib.es5.d.ts#L1480

  •    /**
        * From T, pick a set of properties whose keys are in the union K
        */
       type Pick<T, K extends keyof T> = {
         [P in K]: T[P]
       }
    

  • Exclude<Type, ExcludedUnion>

  • 정의: ExcludedUnion에 할당할 수 있는 모든 공용체 구성원을 Type에서 제외하여 유형을 구성합니다.

  • 문서: https://www.typescriptlang.org/docs/handbook/utility-types.html#excludetype-excludedunion

  • 출처: https://github.com/microsoft/TypeScript/blob/master/lib/lib.es5.d.ts#L1494

  •    /**
        * Exclude from T those types that are assignable to U
        */
       type Exclude<T, U> = T extends U ? never : T
    

    기타 링크



    Marius Schulz의 Egghead 과정Advanced Static Types in TypeScript을 시청해야 합니다.


    Edward LichPixabay 이미지

    오밋이 생각나는 도넛의 구멍 😉

    좋은 웹페이지 즐겨찾기