Say, I have a enum like this:
export enum Lang {
eng = '????',
rus = '????',
jap = '????',
chi = '????',
}
I have a function that accepts a key of that enum and returns its value:
function langToFlag(key) {
return Lang[key];
}
Question: How do I type the argument and the return value of this function?
I expected something like:
function LangToFlag(key: keyof Lang): valueof Lang {
...but keyof
includes all internal Object
properties and valueof
does not exist.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…