我正在从事Angular 9项目。我想使用ResizeObserver,但是由于TypeScript的lib.dom.d.ts(issue)当前缺少此类型,因此我尝试将Jason Strothmann的ResizeObserver.d.ts文件添加到我的项目。
我遵循了this页给出的建议:
<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
目录。src
复制到了ResizeObserver.d.ts
。src/types
的{{1}}数组中添加了"./src/types"
(就像"typeRoots"
一样,它位于tsconfig.json
文件夹中)。
app
中声明了类型为src
的对象,但即使停止并重新启动ResizeObserver
或重新启动VS Code之后,TypeScript也无法识别该类型。我的src/components/foo/foo.component.ts
看起来像这样:
ng serve
TypeScript可以识别所有其他(JavaScript,DOM或与Angular相关的)类型,仅忽略tsconfig.json
中定义的类型。我在做什么错了?
答案 0 :(得分:1)
我发现了问题。我必须将此行添加到tsconfig.json
:
"include": ["./src/types/*.d.ts"]