我正在做一个Angular 9项目。我想使用一个 调整观察者大小但由于目前TypeScript的lib.dom.d.ts中没有这个类型(发出),我试着将Jason Strothmann的 ResizeObserver.d.ts 文件到我的项目中。
我按照 这个 页面。
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"]