问题描述
在以下视频中35:00左右Anders Hejlsberg谈论外部模块时...
When Anders Hejlsberg is talking about external modules around 35:00 in the following video...
...为什么文件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:
- 在引用JavaScript类型定义时,例如大量收集的关于节点,jquery等的定义,请参见: https://github.com/borisyankov/DefinitelyTyped
- 当我们要使用
--out
进行编译时,可以使用/// <reference
引用文件.
- 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
这篇关于什么时候需要三斜杠参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!