[英]VSCode / tslint does not resolve paths in tsconfig.json
vscode is somehow not honoring my tsconfig.json (for a couple of weeks now, it has been different. eiter my bad or vscode update...) vscode 以某种方式不尊重我的 tsconfig.json(几个星期以来,它已经不同了。无论是我的错误还是 vscode 更新......)
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@foo-animation/*": [
"src/app/animation/*"
],
...
Respectively in the Problems tab:分别在问题选项卡中:
Cannot find module '@foo-animation/animation-micro' or its corresponding type declarations.
找不到模块“@foo-animation/animation-micro”或其相应的类型声明。 ts(2307)
ts(2307)
✓ Regular base paths (like @angular/core
) are properly resolved , just my 'custom' ones are the problem... ✓常规基本路径(如
@angular/core
)已正确解决,只有我的“自定义”路径才是问题...
✓ Compiling, Building, Running... all works like a charm. ✓编译、构建、运行......一切都像魅力一样。 So I believe from an angular/typescript-perspective everything is fine.
所以我相信从角度/打字稿的角度来看一切都很好。 (Also, my fellow developers using IntelliJ have no issues…) So it seems to boild down to „telling vscode about it“.... :-/
(另外,我使用 IntelliJ 的开发人员没有问题......)所以它似乎归结为“告诉 vscode 关于它”......:-/
My tsconfig.json
sits in the root-folder of the project.我的
tsconfig.json
位于项目的根文件夹中。 the only thing is, that I use another tsconfig.app.json
, which includes above tsconfig.json
.唯一的事情是,我使用了另一个
tsconfig.app.json
,其中包括tsconfig.json
。
So is there a way to tell vscode where to look for it's tsconfig.json (to encourage parsing those paths) ?那么有没有办法告诉 vscode 在哪里寻找它的 tsconfig.json (鼓励解析这些路径)?
This SO question and this VSCode github issue might be related, but I still don't know what to do. This SO question和this VSCode github issue可能相关,但我仍然不知道该怎么做。
I had a similar issue while setting up my repositories recently and I think adding this line to your vscode settings.json should help:我最近在设置存储库时遇到了类似的问题,我认为将此行添加到您的 vscode settings.json 应该会有所帮助:
"tslint.configFile": "./tslint.json"
If your tslint.json is not in the root you should add your own path.如果您的 tslint.json 不在根目录中,您应该添加自己的路径。
You could use the typeRoots
and types
compileOptions.您可以使用
typeRoots
和types
compileOptions。
typeRoots
by itself tells tsc where to find type definitions. typeRoots
本身告诉 tsc 在哪里可以找到类型定义。 see typeRoots见类型根
"typeRoots": [
"dirPath/@angular",
"node_modules/@types",
"node_modules/electron"
] /* List of folders to include type definitions from. */
Using types
tells it whether there are specific ones that you would like to be resolved.使用
types
告诉它是否有您想要解析的特定types
。 Any other types will be ignored.任何其他类型都将被忽略。 see types
查看类型
"types": [
"animation-micro",
"jquery",
"node",
"react",
"prop-types",
"." //referencing types belonging to paths specified in typeRoots i.e. 'dirPath/@angular/.' , 'node_modules/@types/.' & 'node_modules/electron/.' - needed to resolve namespaces (dependencies)
],
Note: Specifying typeRoots
and types
compileOptions will exclude types that are usually included by default, unless explicitly included.注意:指定
typeRoots
和types
compileOptions 将排除通常默认包含的类型,除非明确包含。
Other helpful alternative, depending on your runtime setup and requirements, could be to use the rootDirs
compileOption.根据您的运行时设置和要求,其他有用的替代方法可能是使用
rootDirs
compileOption。
rootDirs
allows you to treat everything almost like an 'Über jar' in java (the idea of everything being available in one place). rootDirs
允许您将所有内容几乎视为 Java 中的“Über jar”(所有内容都在一个地方可用的想法)。 see rootDirs见根目录
"rootDirs": [
"/ts/",
"/js/",
"src/main/resources/static/ts",
"src/main/resources/static/js"
],/* List of root folders whose combined content represents the structure of the project at runtime. */
Depending on your use case, you may not even need both tsconfig
files anymore using these.根据您的用例,您甚至可能不再需要使用这两个
tsconfig
文件。
Also note, using extends
overwrites the referenced tsconfig
settings, so be careful that you haven't accidentally overwritten some of your paths.另请注意,使用
extends
覆盖引用的tsconfig
设置,因此请注意不要意外覆盖某些路径。 That could also potentially cause issues.这也可能导致问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.