我正在处理一个 Angular 9 项目。我想使用 ResizeObserver ,但由于当前 TypeScript 的 lib.dom.d.ts ( issue ) 中缺少此类型,因此我尝试添加 Jason Strothmann 的 ResizeObserver.d.ts文件到我的项目。
我遵循了 this 给出的建议页:
types
src
下的目录. ResizeObserver.d.ts
进入 src/types
. "./src/types"
到 "typeRoots"
tsconfig.json
中的数组(它在 app
文件夹中,就像 src
一样)。 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"]
关于angular - 自定义 TypeScript 类型定义文件被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61770231/