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 |
Tags
- postgresql
- sqlite
- API
- vscode
- mongo
- react
- frontend
- DM
- C++
- UI
- Three
- figma
- GAN
- DB
- Git
- nodejs
- ps
- PRISMA
- SOLID
- python
- Linux
- js
- CV
- review
- PyTorch
- html
- CSS
- ML
- Express
- ts
Archives
- Today
- Total
아카이브
[TS] Type | 05. Parameters & ReturnType 본문
Parameters
Parameters는 대상 함수 타입에서의 매개변수 타입들을 불러옵니다.
type typeParameter = Parameter<(param: paramTypes) => returnType>
만약 미리 선언된 함수를 사용한다면, 대신 typeof 연산자를 사용할 수 있습니다.
function addToCart(id: string, quantity: number = 1): boolean {
// ...
return true;
}
type AddToCartParameters = Parameters<typeof addToCart>;
// type AddToCartParameters = [id: string, quantity: number | undefined]
ReturnType
ReturnType은 대상 함수 타입에서 반환값의 타입을 불러옵니다.
type typeReturnType = ReturnType<(param: paramTypes) => returnType>
마찬가지로 미리 선언된 함수에 대해 typeof 연산자를 사용할 수 있습니다.
function addToCart(id: string, quantity: number = 1): boolean {
// ...
return true;
}
type AddToCartResult = ReturnType<typeof addToCart>;
// type AddToCartResult = boolean
728x90
'Language > TypeScript' 카테고리의 다른 글
[TS] Type | 04. Pick & Omit (0) | 2024.07.11 |
---|---|
[TS] outDir & rootDir (1) | 2024.07.11 |
[TS] Type | 03. Record (1) | 2024.07.10 |
[TS] Syntax | 07. keyof & typeof (0) | 2024.07.10 |
[TS] Syntax | 06. Union & Intersection (0) | 2024.06.28 |
Comments