【发布时间】:2016-03-11 05:04:45
【问题描述】:
在加载 Typescript(1.6 以上)定义文件时,是否更喜欢使用 ES6 导入或引用路径注释?
import {describe, it, expect, jasmine} from './jasmine'
或
import * as jasmine from './jasmine'
对比
///<reference path="jasmine.d.ts"/>
【问题讨论】:
在加载 Typescript(1.6 以上)定义文件时,是否更喜欢使用 ES6 导入或引用路径注释?
import {describe, it, expect, jasmine} from './jasmine'
或
import * as jasmine from './jasmine'
对比
///<reference path="jasmine.d.ts"/>
【问题讨论】:
@Yudhistira Arya,正如您从 @ahejlsberg ES6 Modules #2242 post 看到的那样
建议更新 TypeScript 库和应用程序以使用新语法,但这不是必需的。新的 ES6 模块语法与 TypeScript 原有的内部和外部模块结构共存,可以随意混合和匹配。
当您的应用程序不使用 node.js 或 require.js 时,您可以使用引用标记 - 这是写在typescript handbook:
不使用 node.js 或 require.js 的应用程序不需要使用外部模块,最好使用内部模块概念进行组织
另外,你可以找到一些信息here
【讨论】:
如果你使用最新的tslint标准配置(tslint:latest),那么会报:
<reference> is not allowed, use imports
所以建议使用 ES6 风格的导入 (source)。
【讨论】: