Typescript, enums and string -


i have hard time converting string coming env variable enum.

here's enum:

enum environment {     test = 1,     development,     production }  export default environment; 

and here's i've been trying:

export default class globalparameters {     public static env: environment = environment[<string>process.env.node_env]; } console.log(process.env.node_env) // gives "development" let str = string(process.env.node_env); // gives "development" console.log(environment[str])  //gives undefined object.seal(globalparameters); 

your code seems work fine:

enum environment {     test = 1,     development,     production }  console.log(environment[2]) // "development" let str = string(environment[2]); console.log(str); // "development" console.log(environment[str]) // 2 

(code in playground)


Comments

Popular posts from this blog

sql - can we replace full join with union of left and right join? why not? -

javascript - Parallax scrolling and fixed footer code causing width issues -

iOS: Performance of reloading UIImage(name:...) -