티스토리 뷰
728x90
// 5. type alias vs. interface
// 5-1. function
interface IFunction {
(name: string, age?: number): void;
}
type tFunction = (name: string, age?: number) => void;
// 5-2. array
type tArray = string[];
interface IArray {
[index: number]: string;
}
// 5-3. intersection
interface ErrorHandling {
success: boolean;
error?: { message: string };
}
interface ArtistData {
artists: { name: string }[];
}
type ArtistsResponseType = ArtistData & ErrorHandling;
interface IArtistsResponse extends ArtistData, ErrorHandling {};
let tar: ArtistsResponseType;
let iar: IArtistsResponse;
// 5-4. union type (only type)
type stringOrNumber = string | number;
// 5-5. declaration merge(only interface)
interface DeclarationMerge {
name: string;
}
interface DeclarationMerge {
age?: number;
}
둘 다 타입을 정의하는 방법인데, interface는 타입을 새로 만드는 것 같고, type은 이미 있는 타입들을 조합해서 이름을 정하는 것 같다.
'웹 개발 > Typescript' 카테고리의 다른 글
class 기본 (readonly, index signatures) (0) | 2022.01.04 |
---|---|
class 기본 (초기화, getter, setter) (0) | 2022.01.04 |
interface 기본 (0) | 2022.01.04 |
function in interface (0) | 2022.01.04 |
optional property in interface (0) | 2022.01.04 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Hardhat
- avalanchego
- eslint
- erc20
- Upgradeable Contracts
- class
- Flutter
- Call
- web3-token
- interface
- 블록 탐색기
- JWT
- ERC721
- ethers.js
- swr
- 앱 아이콘
- caver-js
- 스마트 컨트랙트
- Truffle
- web3.js
- caver.js
- Android
- 블록체인
- ganache
- 이더리움
- typescript
- metamask-extension
- nft
- Proxy Pattern
- web3
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함