我可以在 VSCode IDE 上设置要使用的打字稿配置`tsconfig.json` 路径吗? [英] Can I set a typescript configuration `tsconfig.json` path on the VSCode IDE to use?
问题描述
我的项目结构如下:
<预><代码>.└── 我的应用程序/├── .configs/│ ├── tsconfig.json│ ├── webpack.merge.ts│ ├── webpack.dev.config.ts│ └── webpack.prod.config.ts├── node_modules├── src/│ └── index.tsx└── package.json在命令行上运行 TypeScript tsc --project .configs/tsconfig.json
编译没有问题.但是 VSCode IDE 在 .tsx
中向我显示了错误/警告.我不想禁用 TS 警告,所以这对我不起作用:如何在 VSCode 中禁用 TypeScript 警告?, 为什么 VS Code 会抛出找不到模块 'typescript'.ts(2307)"当模块在那里时?
VSCode 中是否有设置路径,以便 VSCode IDE TypeScript 可以用于当前项目.我知道如果我将 tsconfig.json
放在根目录 (my-app
) 中,VSCode IDE 会按预期工作.但我想将所有配置脚本保存在一个文件夹中,而不是根目录中.VSCode 允许这样做吗?
据我所知,VS Code(或者更准确地说,内置 TS 扩展)不支持将您的配置放在任何其他地方.
>
您可以做的是在您的根目录中放置一个 tsconfig.json
,扩展你的.config/tsconfig.json
.它不是最漂亮的,但是您可以通过 1) 将它添加到您的 .git/info/exclude
以使其忽略它(无需修改 .gitignore
>) 和 2) 将其添加到您的 Files: Exclude
VS Code 选项中,以便在 VS Code 中的资源管理器中隐藏它.
I have a project structure like the following:
.
└── my-app/
├── .configs/
│ ├── tsconfig.json
│ ├── webpack.merge.ts
│ ├── webpack.dev.config.ts
│ └── webpack.prod.config.ts
├── node_modules
├── src/
│ └── index.tsx
└── package.json
Running TypeScript on the commandline tsc --project .configs/tsconfig.json
compiles without issues. But VSCode IDE shows me errors/warnings in the .tsx
. I don't want to disable TS Warnings so this won't work for me: How to disable TypeScript warnings in VSCode?, Why does VS Code throw "Cannot find module 'typescript'. ts(2307)" while the module is there?
Is there a setting in VSCode that I set a path so that VSCode IDE TypeScript can use for the current project. I understand that if I put the tsconfig.json
in the root dir (my-app
) VSCode IDE works as expected. But I would like to keep all configuration scripts in a single folder instead of the root dir. Does VSCode allow for this?
As far as I know, VS Code (or more precisely, the built-in TS extension) doesn't support having your config any other place.
What you could do is placing a tsconfig.json
in your root that extends your .config/tsconfig.json
. It's not the prettiest, but you can make it pretty seamless by 1) adding it to your .git/info/exclude
to make git ignore it (without having to modify .gitignore
) and 2) adding it to your Files: Exclude
VS Code option to hide it from your explorer in VS Code.
这篇关于我可以在 VSCode IDE 上设置要使用的打字稿配置`tsconfig.json` 路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!