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
Comments
Post a Comment