React TypeScript 치트시트에서 TypeScript 생략을 이해하기 위한 전제 조건
7048 단어 reactdevjournaltypescript
소개
내가 배운 자원을 잊어버리지 않도록 자기 자신을 위한 메모.
의 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 -
keyof
및 Omit
에 사용된 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 document 및 sources
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 Lich의 Pixabay 이미지
오밋이 생각나는 도넛의 구멍 😉
Reference
이 문제에 관하여(React TypeScript 치트시트에서 TypeScript 생략을 이해하기 위한 전제 조건), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/dance2die/prerequisite-to-understanding-typescript-omit-in-react-typescript-cheatsheet-4k4b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)