如何在vscode中全局引用*.d.ts

min*_*d1n 5 intellisense reference typescript visual-studio-code typescript-typings

要在 vscode 中为 jasmine 等框架启用智能感知,我们需要在每个打字稿文件的顶部显式引用打字文件,如下所示:

/// <reference path="./node_modules/@types/jasmine/index.d.ts" />
Run Code Online (Sandbox Code Playgroud)

有没有办法全局引用 vscode 中的所有打字文件,这样我们就不需要在每个打字稿文件中引用它们?

Mat*_*ner 3

如果您有tsconfig.jsonnode_modules/@types则应自动获取来自的键入内容。您可以确保您的 TS 文件是您的tsconfig.json您可以通过TypeScript: Go to Project Configuration在 VSCode 中运行命令

如果您有tsconfig.json但仍然没有看到茉莉花类型,请尝试更新您的tsconfig.json以明确包含茉莉花类型:

{
    "compilerOptions": {
        ...
    },
    "typeAcquisition": {
        "include": [
            "jasmine"
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

如果仍然无法正常工作,请提交错误