当我尝试使用字符串Enum Localization
变量访问内部的值时,出现此错误。locale
enum Localization {
'en-US' = '.com',
'pt-BR' = '.com.br',
'en-CA' = '.com.ca',
'en-AU' = '.com.au',
'en-IE' = '.com.ie',
'string' = 'string'
};
Run Code Online (Sandbox Code Playgroud)
const locale:string = 'pt-BR' //This value will come from DB.
const result = Localization[locale];
Run Code Online (Sandbox Code Playgroud)
错误:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof Localization'. No index signature with a parameter of type 'string' was found on type 'typeof Localization'.
在 Javascript 中工作正常。 …