Yudhistira Arya
Yudhistira Arya

Reputation: 3681

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

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"/>

Upvotes: 5

Views: 4809

Answers (2)

Benny Code
Benny Code

Reputation: 54965

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).

Upvotes: 3

Jenya
Jenya

Reputation: 1145

@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

Upvotes: 4

Related Questions