admin管理员组文章数量:1307584
I have a file called types.ts
which has all my types in. I want to export some of these, like so:
export type Example {
something: string;
}
I have another file called index.ts
, which is the entry point for my code. I want to export the Example type. When I try the following:
import { Example } from "./types";
export default {
Example
}
I get the following error:
'Example' only refers to a type, but is being used as a value here.ts(2693)
I'm not sure how to export a type from another file correctly. I have also tried the following:
export * from "./types";
export { Example } from "./types";
But this doesn't work as it's not part of the export, due to my export default
which contains other stuff, however this might be an entirely different issue if this is the correct way to do it.
What's the correct / best way to achieve this?
I have a file called types.ts
which has all my types in. I want to export some of these, like so:
export type Example {
something: string;
}
I have another file called index.ts
, which is the entry point for my code. I want to export the Example type. When I try the following:
import { Example } from "./types";
export default {
Example
}
I get the following error:
'Example' only refers to a type, but is being used as a value here.ts(2693)
I'm not sure how to export a type from another file correctly. I have also tried the following:
export * from "./types";
export { Example } from "./types";
But this doesn't work as it's not part of the export, due to my export default
which contains other stuff, however this might be an entirely different issue if this is the correct way to do it.
What's the correct / best way to achieve this?
Share Improve this question asked Jul 11, 2020 at 22:12 user8826104user88261041 Answer
Reset to default 5When you do
export default {
Example
}
...you're exporting an object literal with an Example
property (written with shorthand notation) as the default export of a module. That means it's expecting Example
to be a variable whose value will be copied to the Example
property of the object being exported. But in your case, Example
is a type, not a variable.
If you want to export Example
as the default export of a module, you'd do it like this:
export default Example;
If you want to export Example
as a named type export, you don't use default
:
export { Example };
本文标签:
版权声明:本文标题:javascript - Type "only refers to a type, but is being used as a value here" when exporting - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741822961a2399476.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论