When do I need a triple slash reference?

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

Leave a Comment