我正在尝试扩展打字稿中的现有枚举。它看起来像在键入时工作,但扩展枚举成员的值是未定义的。
我正在使用node.js 8.0.0和tsc 2.4.2
--- ecategorytype.ts ---
export enum eCategoryType {
generic = 'generic',
resources = 'resources',
friendGroup = 'friendGroup'
}
--- enumextend.ts ---
import eCategoryType from './ecategorytype';
declare module './ecategorytype' {
export enum eCategoryType {
classGroup = 'classGroup',
testGroup = 'testGroup'
}
}
---用法---
import eCategoryType from '../models/category/ecategorytype';
import '../models/category/enumextend';
console.log(eCategoryType.friendGroup);
console.log(eCategoryType.classGroup);
console.log(eCategoryType.testGroup);
--- enumextend.d.ts ---
declare module './ecategorytype' {
enum eCategoryType {
classGroup = "classGroup",
testGroup = "testGroup",
}
}
export {};
--- enumextend.js ---
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=typeext.js.map
---预期的控制台输出----
friendGroup
testGroup
classGroup
---真人控制台输出---
friendGroup
undefined
undefined
请问有什么不对?
答案 0 :(得分:0)
导入错误:
import eCategoryType from '../models/category/ecategorytype';
应该是:
import {eCategoryType} from '../models/category/ecategorytype';