如何在非基于模块的网站的多个文件中使用 VS Code 中的 @ts-check?

How to use @ts-check in VS Code across multiple files with non-module-based website?

我正在尝试创建一个非常简单的网站:

但我希望能够在 VS Code 中使用 TypeScript 的 @ts-checkjsconfig.json,并让它理解 JavaScript 文件中代码的全局范围。但是,我发现它无法跳转到 JavaScript 文件之间的定义(或者至少不一致?)。

有没有办法告诉 TypeScript 编译器所有 JavaScript 文件都在全局范围内,并使用 index.html 中的正确求值顺序?

在 VSC 配置中使用 "js/ts.implicitProjectConfig.checkJs": true(或在文件中使用 // @ts-check)并使用 /// <reference path="[...]" />

引用其他文件
/// <reference path="other.js" />

somethingDefinedInOtherJS; // no error, f12 go to definition works

有关详细信息,请参阅 Triple-Slash Directives TS 文档。