我正在做一个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
)。ResizeObserver
中src/components/foo/foo.component.ts
,但打字稿不承认的类型,甚至没有停止和重新启动后ng serve
,或重新启动VS代码。我的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"]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句