TypeScript
TypeScript type aliases
mykuromi
2024. 2. 4. 09:16
✔️ Type Aliases
- 기존 데이터 타입에 사용자 정의 이름 부여
- 코드 가독성 향상
- 복잡한 타입 구조 단순화
// primitive data type
type Name = string;
const myName: Name = "myKuromi";
// object type
type Me = {
name: string,
level: number
};
const me: Me = {
name: "myKuromi",
level: 99
};
// function
type HelloFunction = (name: string) => string;
const hello: HelloFunction = (name) => `Hello, ${name}!`;