Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do I need a triple slash reference?

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

Anders Hejlsberg: Introducing TypeScript

... why does the file server.ts require a triple slash reference to node.d.ts where as hello.ts doesn't require a similar reference to server.ts?

In particular in hello.ts he mentions that intellisense is present plus he gets to use the exported item from server.ts. So what more could the triple slash reference add?

like image 875
Ian Warburton Avatar asked Mar 27 '14 10:03

Ian Warburton


1 Answers

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

like image 102
basarat Avatar answered Nov 04 '22 23:11

basarat