0

I'm trying to extend an existing enum in typescript. It's look like working when typing but value for extended enum member is undefined.

I'm using node.js 8.0.0 with 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'
    }
}

--- usage ---

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

--- expected console output ----

friendGroup
testGroup
classGroup

--- reality console output ---

friendGroup
undefined
undefined

What could be wrong please?

5
  • Where do you import enumextend.ts? Commented Aug 6, 2017 at 6:12
  • Updated: I tried to call: import '../models/category/enumextend' in usage but still same result. Commented Aug 6, 2017 at 6:26
  • import '../models/category/enumextend'; --- what does this import supposed to do? You run it but don't use any exported identifiers. Commented Aug 6, 2017 at 6:35
  • error TS2305: Module '"src/models/category/enumextend"' has no exported member 'eCategoryType'. if I call import {eCategoryType} from '../models/category/enumextend'; Commented Aug 6, 2017 at 8:32
  • Possible duplicate of TypeScript: extending imported enum Commented Aug 6, 2017 at 12:13

1 Answer 1

0

You import is wrong:

import eCategoryType from '../models/category/ecategorytype';

Should be:

import {eCategoryType} from '../models/category/ecategorytype';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.