我正在为项目中使用的一些常量开发打字稿通用模块。
这是我的文件结构
my-common
├── constants
│ ├── index.ts
│ ├── status.ts
│ └── type.ts
├── dist
│ └── (compiled files)
├── index.ts
├── locales
│ ├── en
│ │ ├── index.ts
│ │ ├── status.ts
│ │ └── type.ts
│ ├── index.ts
│ ├── fr
│ │ ├── index.ts
│ │ ├── status.ts
│ │ └── type.ts
│ └── zh-hk
│ ├── index.ts
│ ├── status.ts
│ └── type.ts
├── node_modules
│ └── (modules)
├── package.json
└── tsconfig.json
还有文件的例子
常量/ status.ts
export enum UserStatus {
INACTIVE = -1,
NOT_VERIFIED = 0,
VERIFIED = 1,
ACTIVE = 10
}
export enum WorkspaceStatus {
INACTIVE = -1,
ACTIVE = 10
}
区域设置/ EN / status.ts
export enum UserStatus {
INACTIVE = "Inactive",
NOT_VERIFIED = "Not Verified",
VERIFIED = "Verified",
ACTIVE = "Active"
}
export enum WorkspaceStatus {
INACTIVE = "Inactive",
ACTIVE = "Active"
}
常量/索引.ts,locales / en / index.ts
import * as status from "./status";
import * as type from "./type";
export { status, type };
区域设置/ index.ts
import * as en from "./en";
import * as tc from "./zh-hk";
import * as fr from "./fr";
const obj = { en, fr, "zh-hk": tc };
export default obj;
index.ts
import * as constants from "./constants";
import locales from "./locales";
export default { ...constants, locales };
Typescript会在 index.ts 导出语句中抛出错误:
[ts] Default export of the module has or is using private name '"/path/to/module/locales/en/index"'.
[ts] Default export of the module has or is using private name '"/path/to/module/locales/fr/index"'.
[ts] Default export of the module has or is using private name '"/path/to/module/locales/zh-hk/index"'.
知道为什么会出现这样的错误及其解决方案。
感谢。
编辑:
当我在 locales / index.ts 上更改导出语句时:
import * as en from "./en";
import * as tc from "./zh-hk";
import * as fr from "./fr";
export default { en, fr, "zh-hk": tc } as any;
现在可以导出它,但在输入common.locales.en
后,VSCode中没有代码完成。