타입 내보내기
typescript 파일에서 어떤 특정한 타입을 export 키워드를 이용해 내보낼 수 있고, import를 이용해 가져다 쓸 수도 있다.
Type export
export interface Uuser {
firstName: string
lastName: string
age:number
isValid: boolean
}
export function getFullName(user: Uuser) {
return `${user.firstName} ${user.lastName}`
}
Type import
import { Uuser, getFullName } from './exportuser'
const gohome: Uuser = {
firstName: 'crust',
lastName: 'cheese',
age: 36,
isValid: false
}
const fullName = getFullName(gohome);
console.log(fullName) // crust cheese
console.log(gohome.isValid) // false
'TYPESCRIPT' 카테고리의 다른 글
[Typescript] 타입스크립트 구성 옵션 (tsconfig.json) (0) | 2023.12.12 |
---|---|
[Typescript] 패키지의 타입선언 (0) | 2023.12.12 |
[Typescript] 제네릭 (Generic) (0) | 2023.12.12 |
[Typescript] 클래스와 접근제어자 (0) | 2023.12.12 |
[Typescript] 함수 오버로딩 (Overloading) (0) | 2023.12.12 |
타입 내보내기
typescript 파일에서 어떤 특정한 타입을 export 키워드를 이용해 내보낼 수 있고, import를 이용해 가져다 쓸 수도 있다.
Type export
export interface Uuser {
firstName: string
lastName: string
age:number
isValid: boolean
}
export function getFullName(user: Uuser) {
return `${user.firstName} ${user.lastName}`
}
Type import
import { Uuser, getFullName } from './exportuser'
const gohome: Uuser = {
firstName: 'crust',
lastName: 'cheese',
age: 36,
isValid: false
}
const fullName = getFullName(gohome);
console.log(fullName) // crust cheese
console.log(gohome.isValid) // false
'TYPESCRIPT' 카테고리의 다른 글
[Typescript] 타입스크립트 구성 옵션 (tsconfig.json) (0) | 2023.12.12 |
---|---|
[Typescript] 패키지의 타입선언 (0) | 2023.12.12 |
[Typescript] 제네릭 (Generic) (0) | 2023.12.12 |
[Typescript] 클래스와 접근제어자 (0) | 2023.12.12 |
[Typescript] 함수 오버로딩 (Overloading) (0) | 2023.12.12 |