[英]Autocomplete for typescript shows wrong path on VSCode
I've been facing some annoying trouble on typescript + VSCode when it comes to autocomplete:在自动完成方面,我在打字稿 + VSCode 上遇到了一些烦人的麻烦:
Whenever I try to autoComplete, it never brings the correct path.每当我尝试自动完成时,它永远不会带来正确的路径。 If I am at
./src/components/foo
and I type Bar
to get it from './src/components/bar/index.tsx', instead of autocomplete completes with import {Bar} from '../bar'
, i always get import {Bar} from 'src/components/bar'
如果我在
./src/components/foo
并且我输入Bar
以从 './src/components/bar/index.tsx' 获取它,而不是通过import {Bar} from '../bar'
自动完成,我总是import {Bar} from 'src/components/bar'
my tsconfig.json
:我的
tsconfig.json
:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"resolveJsonModule": true,
"sourceMap": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"rootDirs": ["src", "stories"],
"allowJs": true,
"baseUrl": ".",
"paths": {
"my-lib": ["./node_modules/my-lib/dist/*"]
}
},
"include": [
"index.d.ts",
"./src/**/*",
"./stories/**/**/*"
]
}
Update Vscode settings更新 Vscode 设置
On VScode File>Preferences>Settings>User Settings在 VScode 文件>首选项>设置>用户设置
"typescript.preferences.importModuleSpecifier": "relative"
从tsconfig.json
删除"baseUrl": ".",
为我解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.