Issue
I have created an enum, but I am having trouble importing and using the enum in VS15.
This is the enum which is contained in enums.ts:
enum EntityStatus {
     New = 0,
     Active = 1,
     Archived = 2,
     Trashed = 3,
     Deleted = 4
}
Visual Studio sees this enum without even importing and so does not give a compile time error. But at runtime, an error is thrown
 Cannot read property 'Archived' of undefined.
So now I try to import it like I import other classes:
 import {EntityStatus} from "../../core/enums";
Visual Studio now gives a compile time error:
 "...enums is not a module ..."
So how do I import the enum?
Solution
I was missing the export keyword:
 export enum EntityStatus {
      New = 0,
      Active = 1,
      Archived = 2,
      Trashed = 3,
      Deleted = 4
 }
Then it worked as expected. (But see @Martin Braun's comment below)
Answered By - Greg Gum
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.