I have string enum declared as follows:
export namespace BootDeviceSelector {
export const noChange: 'None' = 'None';
export type noChange = 'None';
export const PXE_ISCSI: 'Pxe' = 'Pxe';
export type PXE_ISCSI = 'Pxe';
}
export type BootDeviceSelector = BootDeviceSelector.noChange | BootDeviceSelector.PXE_ISCSI;
In my application I have many more such a sets. I need a general mapping function which converts string (coming from backend) to value (example: "None"
=> BootDeviceSelector.noChange
). I don't know how to declare parameters and output of function (maybe something better than any
). I'd expect to pass to this function value to convert and list of values to search in - preferably as namespace name (example: BootDeviceSelector
).
Or one-liner is good enough, something like this:
let a: BootDeviceSelector = (<any>BootDeviceSelector)['Pxe'];
console.log(a);
but here I've got undefined
.
I'm using typescript 2.0.10 and Angular 2.3.1 but I can upgrade, although then I'll leave linting done by codelyzer
package.