Livereload jams my enum declarations (ReferenceError)


#1

Hello,

I use several homemade type definitions containing enums. For exemple “assign” that I reference this way in my “main.ts”

/// <reference path="…/definition/assign.d.ts" />

and containing

declare module assign {

export const enum TransferAssignType {
PICK_UP,
EXCHANGE_AFTER_PICK,
DELIVERY,
STORE,
UNSTORE,
EXCHANGE_BEFORE_DELIVERY
}

It works great using “ionic serve” but once it livereloads I get this error

Dashboard.ngfactory.js:7 ERROR ReferenceError: assign is not defined

for exemple “assign” is used for a switch/case operation that’s look like that at first compilation

case 1 /* EXCHANGE_AFTER_PICK */:

but on live reload it stays like that

case assign.TransferAssignType.EXCHANGE_AFTER_PICK:

Is this a livereload bug or do I declare my enums the wrong way ?


#2

As d.ts is good for typing, values still need to be filled at runtime. But as my enums was const that was not making so much sense. Instead of blaming livereload and ngc for not willing to replace my enum values, I looked for a work around and found a way that look much cleaner than oldschool type definition. (correct me if I am wrong)

So here’s how I solved my problem :

  • use Export keyword instead of declare
  • this imply to rename the file .ts
  • import the module instead of reference it
  • make my enum not const

– import
import {assign} from “./assign”;

– module

export module assign {

export enum MyEnum {
A,
B,
C
}