Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- js
- Three
- react
- CSS
- PRISMA
- frontend
- review
- sqlite
- Linux
- ps
- C++
- vscode
- ts
- PyTorch
- SOLID
- Express
- mongo
- UI
- Git
- API
- DB
- ML
- CV
- python
- backend
- figma
- html
- postgresql
- nodejs
- GAN
Archives
- Today
- Total
아카이브
[TS] Type | 04. Pick & Omit 본문
Pick
Pick은 기존에 존재하던 타입에서 특정 요소만 선택해 구성되는 새로운 타입입니다.
type typePick = Pick<targetType, typeExtracting>;
생성된 타입은 다음과 같이 선택한 요소들만 지니게 됩니다.
interface Product {
id: string;
name: string;
price: number;
membersOnly?: boolean;
}
type ProductInfo = Pick<Product, 'name' | 'price'>;
const product: ProductInfo = {
name: "shirt";
price: "120";
}
Omit
Omit은 기존에 존재하던 타입에서 특정 요소만 제외해 구성되는 새로운 타입입니다.
type typeOmit = Omit<targetType, typeIgnoring>;
생성된 타입은 다음과 같이 선택하지 않은 요소들만 지니게 됩니다.
interface Product {
id: string;
name: string;
price: number;
membersOnly?: boolean;
}
type ProductInfo = Omit<Product, 'id' | 'membersOnly'>;
const product: ProductInfo = {
name: "shirt";
price: "120";
}
728x90
'Language > TypeScript' 카테고리의 다른 글
[TS] Type | 05. Parameters & ReturnType (0) | 2024.07.12 |
---|---|
[TS] outDir & rootDir (0) | 2024.07.11 |
[TS] Type | 03. Record (0) | 2024.07.10 |
[TS] Syntax | 07. keyof & typeof (0) | 2024.07.10 |
[TS] Syntax | 06. Union & Intersection (0) | 2024.06.28 |