模块

最后更新于:2022-04-02 03:28:19

[TOC] ## 概述 导出 ``` export interface StringValidator { isAcceptable(s: string): boolean; } export const test_name:string="test_name" ``` 导入 ``` import {test_name, StringValidator} from "./Validation"; ``` ## 导出重命名 ``` const test_name:string="test_name" export {test_name as name} //导入 import {name} from "./Validation"; ``` ## 导入重命名 `import {name as name2} from "./Validation";` ## 导入整个模块给一个变量 ``` import * as validator from "./ZipCodeValidator"; let myValidator = new validator.ZipCodeValidator(); ``` ## default 默认导出(不需要大括号) ``` //导出 let test_name:string="test_name" export default test_name //导入 import test_name from "./Validation" console.log(test_name); ```
';