如何解决导出类型的打字稿问题
我尝试编译入口TS文件,并发生以下问题:
> tsc --project ./tsconfig.build.json
src/index.ts:2:1 - error TS1128: Declaration or statement expected.
2 export type { Icon } from './component/Button';
~~~~~~
src/index.ts:2:13 - error TS1005: ';' expected.
2 export type { Icon } from './component/Button';
~
src/index.ts:2:27 - error TS1005: ';' expected.
2 export type { Icon } from './component/Button';
~~~~~~~~~~~~~~~~~~~~
index.ts
文件的内容如下:
export { default as Button,Size,ButtonStyle,colors } from './component/Button';
export type { Icon } from './component/Button';
tsconfig.build.json
文件的内容如下:
{
"compilerOptions": {
"module": "commonjs","target": "es5","sourceMap": true,"resolveJsonModule": true,"declaration": true,"outDir": "./dist","jsx": "react","esModuleInterop": true,"allowSyntheticDefaultImports": true,"isolatedModules": false,},"include": [
"src/**/*"
]
}
对于export type {xxx}
中没有index.ts
的文件,它们已成功编译。而且,如果我从该文件中删除了export type { Icon } from './component/Button'
,该问题将消失。但是,我需要将这些对象放在另一个文件中。
有什么主意吗?
解决方法
请尝试将"module": "commonjs"
更改为"module": "esnext",
。
commonjs不支持导出/导入语法。
请在此处查看更多详细信息: https://flaviocopes.com/commonjs/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。