typescript - `///<reference types="react-scripts"/>` 是什么意思?我们可以在 *.d.ts 中使用什么其他类似 xml 的语法?

标签 typescript

在普通的 *.d.ts 文件(typescript 的定义文件)中,我们可以正常使用


declare ***

export interface ***



但也有这个
/// <reference types="react-scripts" />

由 create-react-app 生成,这是什么意思,我们实际上可以在 *.d.ts 文件中使用类似 xml 的语法吗?我们还可以使用哪些其他语法?

最佳答案

一个 /// <reference types="..." />指令声明对包的依赖。

解析这些包名的过程类似于在 import 语句中解析模块名的过程。将这些三斜杠引用类型指令视为声明包的导入的一种简单方法。

例如,包括 /// <reference types="node" />在声明文件中声明此文件使用在 @types/node/index.d.ts 中声明的名称因此,这个包需要与声明文件一起包含在编译中。

仅当您手动创作 d.ts 文件时才使用这些指令。更多信息:https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

在您的情况下,/// <reference types="react-scripts" />导入在 node_modules/react-scripts/lib/react-app.d.ts 中声明的各种名称文件。

希望这可以帮助。

关于typescript - `///<reference types="react-scripts"/>` 是什么意思?我们可以在 *.d.ts 中使用什么其他类似 xml 的语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60628874/

相关文章:

javascript - karma 测试 : measure coverage for untested code

angular - 如何在订阅期间检查 Angular 5 RxJS Observable 的 NULL 结果?

typescript - 如何在 TypeScript 中输入 Redux actions 和 Redux reducer?

javascript - 在外部文件的 typescript 中声明 var 获取 ReferenceError : . .. 未定义

javascript - 将两个不同类 rxjs 的两个不同可观察值分组

angular - 保护 Angular 5 应用程序免受模板中未定义数组插值的影响

javascript - Angular Tour of Heroes 中的 subscribe 方法内部发生了什么?

javascript - Angular 2 typescript 调用javascript函数

typescript - 错误 TS2307 : Cannot find module (but it can when running the js)

html - Angular 点击事件绑定(bind)无法正常工作