最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Typescript. Are Triple-Slash references still required when using "import from" - Stack Overflow

programmeradmin2浏览0评论

In old versions of Typescript it was required to add the famous

/// <reference

label to add the required references. Now after version 1.6 we can import dependencies using the remended ES6 way

import Greeter from "./greeter";

I have been reading for a while but it is still not clear to me whether and why the triple-slash references must be pletely avoided or not.

BTW. Will now the piler know in which order it has to pile the TS files if we are using filesGlob instead of files in the tsconfig.json?

In old versions of Typescript it was required to add the famous

/// <reference

label to add the required references. Now after version 1.6 we can import dependencies using the remended ES6 way

import Greeter from "./greeter";

I have been reading for a while but it is still not clear to me whether and why the triple-slash references must be pletely avoided or not.

BTW. Will now the piler know in which order it has to pile the TS files if we are using filesGlob instead of files in the tsconfig.json?

Share Improve this question asked Apr 8, 2016 at 14:22 iberbeuiberbeu 16.2k6 gold badges29 silver badges49 bronze badges 1
  • If you want to write es6/amd/monjs modules - you will use import. If you want to have single file project - you can use namespaces and reference. – lujcon Commented Apr 8, 2016 at 14:41
Add a ment  | 

2 Answers 2

Reset to default 5 +50

First off, I don't believe filesGlob is officially supported yet: https://github./Microsoft/TypeScript/issues/1927

Now as far as the triple slash reference, it is not required as long as everything is referenced in files in tsconfig.json.

You'll find that if you use a tool like tsd or typings to manage type definitions for your external libraries, they will create a single file that you include in tsconfig.json; that single file will use triple slash references to include the rest of the files.

You can find more information about triple slash references in the TypeScript Handbook

When using internal modules/namespaces we need the ///<reference in order to tell the piler what depends on what in order to build a dependency graph and sort the files in the right order.

The ES6 way that you describe are (external) modules, see https://github./Microsoft/TypeScript/issues/2242. As such, the ordering for concatenation is not relevant as these are loaded asynchronously.

So using ES6 modules, you do not need ///<references.

As for fileGlobs, this is not implemented in TypeScript (yet), but even when it is, I think it's unlikely that it will change anything about the dependency resolution of the files in the project. Even in atom-typescript where they implement fileGlobs, they are very opinionated against code that "depends on any form of js ordering" and they don't support in any other way than manually ordering the files in tsconfig.json.

发布评论

评论列表(0)

  1. 暂无评论