NumberFour / n4js

Type-Safety of Java & Javascript Flexibility
http://numberfour.github.io/n4js/
38 stars 8 forks source link

String based enums no runtime type which leads to runtime exceptions #387

Closed yoosiba closed 6 years ago

yoosiba commented 7 years ago

String based enums have no runtime manifestation of the type which leads to runtime exceptions

// module Defs
export public enum X{
    X1 : "x one"
}

@StringBased
export public enum Y{
    Y1 : "y one"
}

//caller module
import {X} from "Defs";
import {Y} from "Defs";

console.log(X) // { [Function: X] X1: X { name: 'X1', value: 'x one' } }
console.log(Y) // undefined
console.log(N4Type.of(X).fqn); // Defs.X
console.log(N4Type.of(Y).fqn); // runtime error

runtime output

{ [Function: X] X1: X { name: 'X1', value: 'x one' } }
undefined
Defs.X
(SystemJS) Cannot read property 'fqn' of undefined
    TypeError: Cannot read property 'fqn' of undefined
        at execute (/Users/me/work/workspace/MyProj/src-gen/es/MyProj/Caller.js:18:29)
    Error loading MyProj/Caller