Should I use ES6 import or reference path when loading Typescript definition file?

本小妞迷上赌 提交于 2019-12-10 15:27:24

问题


Would it be preferred to use ES6 import or reference path comment when loading Typescript (1.6 above) definition files?

import {describe, it, expect, jasmine} from './jasmine'

or

import * as jasmine from './jasmine'

vs.

///<reference path="jasmine.d.ts"/>


回答1:


@Yudhistira Arya, as you can see from @ahejlsberg ES6 Modules #2242 post

It is recommended that TypeScript libraries and applications be updated to use the new syntax, but this is not a requirement. The new ES6 module syntax coexists with TypeScript's original internal and external module constructs and the constructs can be mixed and matched at will.

You can use reference tag when your application does not use node.js or require.js - this is written in typescript handbook:

Applications not using node.js or require.js do not need to use external modules and can best be organized using the internal module concept

Also, some information you can find here




回答2:


If you use the latest tslint standard configuration (tslint:latest), then it will report:

<reference> is not allowed, use imports

So it is recommended to use ES6-style imports (source).



来源:https://stackoverflow.com/questions/34119270/should-i-use-es6-import-or-reference-path-when-loading-typescript-definition-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!