export/import
StringValidator.ts
expoer interface StringValidator {
isAccetable(s: string): boolean,
}
ZipCodeValidator.ts
import { StringValidator } from "./StringValidator"
위와 같이 module을 export하고 import 해올 수 있다.
type-only export/import
타입 스크립트는 import 해올 때 type도 자동으로 import 해오기 때문에
런타임에서 type만 import 해오는 문장은 지워버린다.
때문에 문장만 가지고 type인지 value인지 알 수 없을 경우 문제가 발생할 수 있다.
그래서 TypeScript 3.8부터 type만 export, import하는 것을 명확히 명시할 수 있도록
type-only imports/exports가 추가되었다.
import type { myType } from './module.ts'
export type { myType };
위 문장들은 runtime에서 실행될 때 삭제된다.
참고
'Frontend > TypeScript' 카테고리의 다른 글
[TS] 제너릭 (0) | 2022.02.28 |
---|---|
[TS] Interface & Class (0) | 2022.02.28 |
[TS] 타입 스크립트의 타입 (0) | 2022.02.28 |
[TS] TypeScript Install & Setting (0) | 2022.02.28 |