自定义TypeScript类型定义文件被忽略。

问题描述 投票:0回答:1

我正在做一个Angular 9项目。我想使用一个 调整观察者大小但由于目前TypeScript的lib.dom.d.ts中没有这个类型(发出),我试着将Jason Strothmann的 ResizeObserver.d.ts 文件到我的项目中。

我按照 这个 页面。

  1. 我创建了一个 types 目录下 src.
  2. 我复制了 ResizeObserver.d.ts 变成 src/types.
  3. 我补充道 "./src/types""typeRoots" 阵中 tsconfig.json (它在 app 文件夹,就像 src).
  4. 我声明了一个类型为 ResizeObserversrc/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 被忽略. 我到底做错了什么?

angular typescript visual-studio-code tsconfig type-definition
1个回答
1
投票

我找到了问题所在。我不得不把这行添加到 tsconfig.json:

"include": ["./src/types/*.d.ts"]
© www.soinside.com 2019 - 2024. All rights reserved.