本文介绍了什么时候需要三斜杠参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下视频中35:00左右Anders Hejlsberg谈论外部模块时...

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

Anders Hejlsberg:引入TypeScript

...为什么文件server.ts需要对node.d.ts的三斜杠引用,而hello.ts不需要对server.ts的相似引用?

... 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?

尤其是在hello.ts中,他提到存在智能感知,并且可以使用从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?

推荐答案

在两种情况下,您需要三斜杠引用:

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/borisyankov/DefinitelyTyped
  • When we want to compile using --out you can reference your files using /// <reference.

使用外部模块(即amd/commonjs)时,需要一个import/require组合键.如果您不知道这些含义是什么(amd/commonjs是javascript术语,不是特定于打字稿的),则不必担心.只需使用/// <reference并使用--out进行编译.

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:我有一个有关内部和外部模块的视频教程: http://www.youtube .com/watch?v = KDrWLMUY0R0& hd = 1

PS: I have a video tutorial on internal vs. external modules : http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

对于新项目,请使用tsconfig.json代替参考注释: http://basarat.gitbooks.io/typescript/content/docs/project/compilation-context.html

Please use tsconfig.json for new projects instead of reference comments : http://basarat.gitbooks.io/typescript/content/docs/project/compilation-context.html

这篇关于什么时候需要三斜杠参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:21