【问题标题】:Can I set a typescript configuration `tsconfig.json` path on the VSCode IDE to use?我可以在 VSCode IDE 上设置要使用的打字稿配置 `tsconfig.json` 路径吗?
【发布时间】:2021-10-08 00:18:05
【问题描述】:

我的项目结构如下:

.
└── my-app/
    ├── .configs/
    │   ├── tsconfig.json
    │   ├── webpack.merge.ts
    │   ├── webpack.dev.config.ts
    │   └── webpack.prod.config.ts
    ├── node_modules
    ├── src/
    │   └── index.tsx
    └── package.json

在命令行tsc --project .configs/tsconfig.json 上运行 TypeScript 编译没有问题。但是 VSCode IDE 在.tsx 中向我显示了错误/警告。我不想禁用 TS 警告,所以这对我不起作用:How to disable TypeScript warnings in VSCode?Why does VS Code throw "Cannot find module 'typescript'. ts(2307)" while the module is there?

在 VSCode 中是否有我设置路径的设置,以便 VSCode IDE TypeScript 可以用于当前项目。我知道如果我将tsconfig.json 放在根目录 (my-app) 中,VSCode IDE 会按预期工作。但我想将所有配置脚本保存在一个文件夹而不是根目录中。 VSCode 允许这样做吗?

【问题讨论】:

标签: typescript vscode-settings vscode-extensions tsconfig tsconfig-paths


【解决方案1】:

据我所知,VS Code(或更准确地说,内置的 TS 扩展)不支持将您的配置放在任何其他位置。

你可以做的是在你的根目录中放置一个tsconfig.jsonextends 你的.config/tsconfig.json。它不是最漂亮的,但是您可以通过以下方式使其非常无缝:1)将其添加到您的 .git/info/exclude 以使 git 忽略它(无需修改 .gitignore)和 2)将其添加到您的 Files: Exclude VS Code 选项在 VS Code 中对浏览器隐藏它。

【讨论】:

    猜你喜欢
    • 2017-04-24
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    • 2016-01-23
    • 2020-07-29
    相关资源
    最近更新 更多