【发布时间】:2022-08-02 20:57:23
【问题描述】:
我尝试使用tsx 运行由 JavaScript 和 Typescript 模块组成的 NodeJS 应用程序。 JavaScript 模块是 ESM,而不是 CommonJS。例如我有这些文件:
// provider.ts
export funcA(p: unknown): unknown {...}
// consumer.js
import * as provider from \"./provider.ts\"
provider.funcA(\"foo\");
它与 tsx 一起运行得很好。 VSCode 的智能感知在 TS 文件中运行良好,但在 JS 文件中却不行。当我悬停provider 它显示import provider 并且我没有完成任何事情。
这是我的tsconfig.json:
{
\"compilerOptions\": {
\"module\": \"NodeNext\",
\"target\": \"ESNext\",
\"allowJs\": true,
\"strict\": true,
},
\"include\": [
<the directory containing both JS and TS files>
],
}
如何让 Intellisense 在 VSCode 中用于 JS 文件中的 TS 导入?
-
你必须让它把 ts 编译成 js - javascript 就是不能加载 ts 文件
-
就像我说的,我可以毫无问题地使用 tsx 运行我的代码。我的问题只是关于 VSCode 中的智能感知。 VSCode 嵌入了 TypeScript 编译器,因此它应该能够理解 JS 和 TS 并提供类型信息。
标签: javascript typescript visual-studio-code es6-modules tsx