当前位置:网站首页>LayaBox---TypeScript---Three slash instructions
LayaBox---TypeScript---Three slash instructions
2022-08-02 10:11:00 【Gamla granite】
目录
1介绍
三斜线指令是包含单个xml标签的单行注释.The content of the comment is used as a compiler directive.
A triple-slash directive can only be placed at the top of the file that contains it.如果它们出现在一个语句或声明之后,那么它们会被当做普通的单行注释,并且不具有特殊的涵义.
/// <reference path="..." />
指令是三斜线指令中最常见的一种. 它用于声明文件间的 依赖.
当使用--out
或--outFile
时,It can also be used as a way to adjust the order of output content. The position of the files in the output file content is consistent with the preprocessed input order.
2.预处理输入文件
The compiler preprocesses the input file to resolve all triple-slash quoting directives. 在这个过程中,Additional files are added to the compilation process.
This process will take some根文件开始; They are files specified on the command line or in tsconfig.json
中的"files"
files in the list. These root files are preprocessed in the specified order. Before a file is added to the list,All triple-slash references it contains are processed,And the goals they contain. Triple-slash references are in the order in which they appear in the file,Use depth-first parsing.
3.错误
Referencing a file that does not exist will result in an error. A file that references itself with a triple slash directive will report an error.
4.使用 --noResolve
如果指定了--noResolve
编译选项,Triple-slash references are ignored;They do not add new files,Also does not change the order of the given files.
与 /// <reference path="..." />
指令相似,这个指令是用来声明 依赖的; 一个 /// <reference types="..." />
指令则声明了对某个包的依赖.
Parsing the names of these packages and in import
The parsing of the module name in the statement is similar. You can simply think of triple-slash type reference directives as import
声明的包.
例如,把 /// <reference types="node" />
Imported into the declaration file,Indicates that this file is used @types/node/index.d.ts
The name declared inside; 并且,This package needs to be included along with the declaration file at compile time.
Only if you need to write oned.ts
file only use this command.
For those declaration files generated during the compilation phase,The compiler will add it automatically/// <reference types="..." />
; 当且仅当Declarations from the referenced package are only added to the generated declarations file when the resulting file uses them/// <reference types="..." />
语句.
若要在.ts
A pair is declared in the file@types
包的依赖,使用--types
命令行选项或在tsconfig.json
里指定.
/// <reference no-default-lib="true"/>
This directive marks a file as 默认库. 你会在 lib.d.ts
See this note at the top of the file and its different variants.
This directive tells the compiler during the compilation process不要Include this default library(比如,lib.d.ts
). This is the same as using on the command line --noLib
相似.
还要注意,当传递了--skipDefaultLibCheck
时,The compiler just ignores the check with /// <reference no-default-lib="true"/>
的文件.
/// <amd-module />
默认情况下生成的AMDModules are anonymous. 但是,Problems arise when some tools need to process the generated modules,比如 r.js
.
amd-module
The directive allows an optional module name to be passed to the compiler:
//amdModule.ts
///<amd-module name='NamedModule'/>
export class C {
}
这会将NamedModule传入到AMD define函数里:
//amdModule.js
define("NamedModule", ["require", "exports"], function (require, exports) {
var C = (function () {
function C() {
}
return C;
})();
exports.C = C;
});
/// <amd-dependency />
注意:This directive is deprecated.使用
import "moduleName";
语句代替.
/// <amd-dependency path="x" />
tells the compiler that there is a nonTypeScriptModule dependencies need to be injected,as the target modulerequire
调用的一部分.
amd-dependency
Directives can also take an optionalname
属性;它允许我们为amd-dependencyPass in an optional name:
/// <amd-dependency path="legacy/moduleA" name="moduleA"/>
declare var moduleA:MyType
moduleA.callStuff()
生成的JavaScript代码:
define(["require", "exports", "legacy/moduleA"], function (require, exports, moduleA) {
moduleA.callStuff()
});
边栏推荐
- 从零开始Blazor Server(5)--权限验证
- 迭代器失效问题
- This article takes you to understand the commonly used models and frameworks of recommender systems
- Using the TCP protocol, will there be no packet loss?
- HikariCP database connection pool, too fast!
- R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化水平柱状图(条形图)、使用orientation参数设置柱状图转置为条形图
- LayaBox---TypeScript---声明合并
- 【技术分享】OSPFv3基本原理
- The R language uses the ggtexttable function of the ggpubr package to visualize the table data (draw the table directly or add the table data to the image), set the theme parameter to customize the fi
- 利用二维数据学习纹理三维网格生成(CVPR 2020)
猜你喜欢
随机推荐
Smoothing of time series data in R language: smoothing time series data to remove noise using the dpill function and locpoly function of the KernSmooth package
This article takes you to understand the commonly used models and frameworks of recommender systems
牛客网项目2.7开发注册功能 报错This application has no explicit mapping for /error......
刷题错题录1-隐式转换与精度丢失
Chapter 15 Generics
牛客刷题——剑指offer(第三期)
The love-hate relationship between C language volatile keyword, inline assembly volatile and compiler
行为型模式-模板方法模式
瑞萨RZ/G2L处理器详细测评
LayaBox---TypeScript---声明合并
Shell脚本实现多选DNS同时批量解析域名IP地址(新更新)
c#反射和特性
从零开始Blazor Server(5)--权限验证
迭代器失效问题
The ggline function of the R language ggpubr package visualizes grouped line graphs, the add parameter is mean_se and dotplot to visualize line graphs of different level averages, and adds error bars
如何选择一块真正“好用的、性能高”的远程控制软件
Event 对象,你很了解吗?
Mistakes in Brushing the Questions 1-Implicit Conversion and Loss of Precision
关于缓存数据的探讨
软件测试之发现和解决bug