When do I need a triple slash reference?

前端 未结 1 576
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 05:47

When Anders Hejlsberg is talking about external modules around 35:00 in the following video...

Anders Hejlsberg: Introducing TypeScript

... why does the file

相关标签:
1条回答
  • 2020-12-03 06:14

    You need a triple slash reference in two scenarios:

    • When you are referencing JavaScript type definitions e.g. definitions for node, jQuery, etc. for a great collection see : https://github.com/DefinitelyTyped/DefinitelyTyped
    • When we want to compile using --out you can reference your files using /// <reference.

    You need a import/require combo when using external modules i.e. amd/commonjs. If you don't know what these mean (amd/commonjs are javascript terms, not specific to typescript) you don't have to care. Just use /// <reference and compile with --out.

    PS: I have a video tutorial on internal vs. external modules: TypeScript Modules Demystified : Internal, AMD with RequireJS, CommonJS with NodeJS

    Update:

    Please use tsconfig.json for new projects instead of reference comments : https://basarat.gitbook.io/typescript/project/compilation-context

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