angular - 自定义 TypeScript 类型定义文件被忽略
问题描述
我正在做一个 Angular 9 项目。我想使用ResizeObserver,但由于 TypeScript 的 lib.dom.d.ts ( issue ) 目前缺少这种类型,我尝试将 Jason Strothmann 的ResizeObserver.d.ts文件添加到我的项目中。
我遵循了这个页面给出的建议:
- 我
types
在src
. - 我复制
ResizeObserver.d.ts
到src/types
. - 我添加
"./src/types"
到"typeRoots"
数组中tsconfig.json
(它在app
文件夹中,就像src
)。 - 我声明了一个 in 类型的对象
ResizeObserver
,src/components/foo/foo.component.ts
但 TypeScript 无法识别该类型,即使在停止和重新启动ng serve
或重新启动 VS Code 之后也是如此。
我的tsconfig.json
样子是这样的:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./out-tsc",
"sourceMap": true,
"declaration": false,
"importHelpers": true,
"experimentalDecorators": true,
"moduleResolution": "Node",
"module": "ES2015",
"target": "ES2015",
"typeRoots": ["./src/types", "./node_modules/@types"],
"lib": ["ES2015", "DOM", "DOM.Iterable"]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
},
"files": ["./src/main.ts"]
}
所有其他(JavaScript、DOM 或 Angular 相关)类型都可以被 TypeScript 识别,只有在中定义的类型ResizeObserver.d.ts
会被忽略。我究竟做错了什么?
解决方案
我发现了问题。我不得不将此行添加到tsconfig.json
:
"include": ["./src/types/*.d.ts"]
推荐阅读
- google-apps-script - Gmail 脚本 - 添加和删除标签的标签
- c - 调试断言失败:使用 CLion 在 C 中读取文件
- python-3.x - 如何构建流程树?
- npm - 如何找到尝试在启动时创建错误目录的 NPM 的配置
- c - 我的项目每次都有不同的结果
- python - 组合两个 if 语句时出现 TypeError 问题
- excel - 使用封闭 XML 导出 .xlsx/.xls
- amazon-web-services - 创建 ec2 实例时播放的 ansible 未定义变量
- amazon-web-services - 在 AWS Athena 中创建存储桶表
- vhdl - VIVADO 测试台输出错误说顶部是黑盒