I'm working on an Angular 9 project. I'd like to use a ResizeObserver, but since this type is currently missing from TypeScript's lib.dom.d.ts (issue), I tried to add Jason Strothmann's ResizeObserver.d.ts file to my project.
I followed the advice given by this page:
- I created a
types
directory undersrc
. - I copied
ResizeObserver.d.ts
intosrc/types
. - I added
"./src/types"
to the"typeRoots"
array intsconfig.json
(it's in theapp
folder, just likesrc
). - I declared an object of type
ResizeObserver
insrc/components/foo/foo.component.ts
, but TypeScript did not recognize the type, not even after stopping and restartingng serve
, or restarting VS Code.
My tsconfig.json
looks like this:
{
"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"]
}
All other (JavaScript, DOM- or Angular-related) types are recognized by TypeScript, only the types defined in ResizeObserver.d.ts
are ignored. What am I doing wrong?