【发布时间】:2018-04-28 16:30:20
【问题描述】:
我开始尝试一些 TypeScript 功能,我想在一个模块中导出两个常量并将它们导入并在另一个模块中使用,如下所示:
// module1.ts
export const CAMPUS = 'campus';
export const TOKIO = 'tokio';
// module2.ts
import * as ThemeNameEnum from './module1';
export type IState = ThemeNameEnum.CAMPUS | ThemeNameEnum.TOKIO;
VSCode 无法识别导出的成员,编译器给我这个错误:
ERROR in /Users/elias/Documents/agora-binaria/crm-front/src/app/redux/theme/theme-reducer.ts (4,36): Namespace '"/Users/elias/Documents/agora-binaria/crm-front/src/app/redux/theme/theme-name-enum"' has no exported member 'CAMPUS'.
ERROR in /Users/elias/Documents/agora-binaria/crm-front/src/app/redux/theme/theme-reducer.ts (4,59): Namespace '"/Users/elias/Documents/agora-binaria/crm-front/src/app/redux/theme/theme-name-enum"' has no exported member 'TOKIO'.
我做错了什么?谢谢。
PS:这是我的tsconfig.json 文件:
{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2017"
],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"removeComments": true,
"outDir": "../dist/client",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
]
},
"exclude": [
"node_modules"
]
}
【问题讨论】:
-
您使用什么编译器设置?你有可以给我们看的
tsconfig.json吗? -
我已经用 tsconfig.json 文件内容@TomFenech 更新了我的答案
标签: typescript