[英]Intellisense shows 'typeof import "/path"' - how to get intellisense of imported variables?
When I import some data and hover over the variable, it shows 'typeof import "/some/path"'
instead of a list of the variables.当我在变量上导入一些数据和 hover 时,它显示
'typeof import "/some/path"'
而不是变量列表。
I would like it to show the list to enable autocomplete and such things.我希望它显示列表以启用自动完成和类似的东西。
I made an example project .我做了一个示例项目。
If you hover over theme1
in index.ts
of that project, it shows vars: typeof import("some/path");
如果您在该项目的 index.ts 中
index.ts
over theme1
,它会显示 vars: typeof import("some/path");
The way it happens is:它发生的方式是:
A folder has files with named exports.一个文件夹包含带有命名导出的文件。 There is an index.ts file which exports everything from that folder:
有一个 index.ts 文件可以导出该文件夹中的所有内容:
//stuff/variables/index.ts
export * from '.';
. .
//stuff/variables/vars1.ts
const stuff1 = 'stuff1';
const stuff2 = 'stuff2';
const stuff3 = 'stuff3';
export { stuff1, stuff2, stuff3 };
A file in the parent folder imports all from that index.ts file, and exports it as a variable:父文件夹中的文件从该 index.ts 文件导入所有内容,并将其导出为变量:
//stuff/index.ts
import * as variablesData from './variables/index';
export const vars = variablesData;
Another file imports that variable and includes it in an exported object:另一个文件导入该变量并将其包含在导出的 object 中:
//stuff/theme.ts
import { vars } from './index';
const obj = {
blue: 'blue',
};
export const theme1 = {
...obj,
vars,
};
And lastly, the top index.ts imports that named export.最后,名为 export 的顶级 index.ts 导入。
//index.ts
import { theme1 } from './stuff/theme';
console.log(theme1);
If I hover over that imported variable, it doesn't list the variables, but instead it shows typeof import("some/path");
如果我 hover 在那个导入的变量上,它不会列出变量,而是显示
typeof import("some/path");
So the export * from '.'
所以
export * from '.'
is not resolved by intellisense.不是由智能感知解决的。 Can't I use `"export *"?
我不能使用 `"export *" 吗?
Can this be helped by adding some type or writing it in a different way?这可以通过添加某种类型或以不同的方式编写来帮助吗?
I believe that what you are describing is a bug/missing feature in Typescript itself.我相信您所描述的是 Typescript 本身的错误/缺失功能。 Though I did not find it among github issues upon doing an ultra quick search there.
虽然我在那里进行超快速搜索后没有在 github 问题中找到它。
What you can do is define the vars
variable directly in vars1.ts
file.您可以做的是直接在
vars1.ts
文件中定义vars
变量。
//stuff/variables/vars1.ts
const stuff1 = 'stuff1';
const stuff2 = 'stuff2';
const stuff3 = 'stuff3';
const vars = { stuff1, stuff2, stuff3 };
export { stuff1, stuff2, stuff3, vars };
Then adjust your index file然后调整你的索引文件
//stuff/index.ts
export { vars } from './variables/index';
and your intellisense will work beautifully.你的智能感知会很好地工作。
Yes this approach is a little bit more work than you did, but at least the types work now:).是的,这种方法比您做的要多一些工作,但至少这些类型现在可以工作了:)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.