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

时间:2020-05-13 08:53:17

标签: angular typescript visual-studio-code tsconfig type-definition

我正在从事Angular 9项目。我想使用ResizeObserver,但是由于TypeScript的lib.dom.d.ts(issue)当前缺少此类型,因此我尝试将Jason Strothmann的ResizeObserver.d.ts文件添加到我的项目。

我遵循了this页给出的建议:

  1. 我在<script> $("#addGroup").on("click", function() { var HtmlCodeOfSection = '<form action="static/phpFiles/test.php" class="dropzone mx-3" id="my-awesome-dropzone-1"></form>'; $(".groups-section").append(HtmlCodeOfSection); Dropzone.options.myAwesomeDropzone = { paramName: "file", // The name that will be used to transfer the file maxFilesize: 5, // MB accept: function(file, done) { done(); } }; } </script> 下创建了一个types目录。
  2. 我将src复制到了ResizeObserver.d.ts
  3. 我在src/types的{​​{1}}数组中添加了"./src/types"(就像"typeRoots"一样,它位于tsconfig.json文件夹中)。
  4. 我在app中声明了类型为src的对象,但即使停止并重新启动ResizeObserver或重新启动VS Code之后,TypeScript也无法识别该类型。

我的src/components/foo/foo.component.ts看起来像这样:

ng serve

TypeScript可以识别所有其他(JavaScript,DOM或与Angular相关的)类型,仅忽略tsconfig.json中定义的类型。我在做什么错了?

1 个答案:

答案 0 :(得分:1)

我发现了问题。我必须将此行添加到tsconfig.json

"include": ["./src/types/*.d.ts"]