Typescript. Are Triple-Slash references still required when using “import from”

后端 未结 2 2158
小蘑菇
小蘑菇 2021-02-05 12:25

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

/// 

label to add the required references. Now after version

相关标签:
2条回答
  • 2021-02-05 12:47

    When using internal modules/namespaces we need the ///<reference in order to tell the compiler 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.com/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 讨论(0)
  • 2021-02-05 12:50

    First off, I don't believe filesGlob is officially supported yet: https://github.com/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

    0 讨论(0)
提交回复
热议问题