我试图解决一个typescript挑战,在第Resistors[val]
行遇到了这个问题Element implicitly has an 'any' type because index expression is not of type 'number'.
.我不确定我做错了什么.如果有人能在这里指点我,那真的很有帮助.提前感谢!
enum Resistors {
Black = 0,
Brown = 1,
Red = 2,
Orange = 3,
Yellow = 4,
Green = 5,
Blue = 6,
Violet = 7,
Grey = 8,
White = 9
}
export function decodedValue(labels : string[]) {
let valuesArr: string[] = labels.map((value: string) => {
const val: string = value.charAt(0).toUpperCase() + value.slice(1);
return Resistors[val];
});
return Number(valuesArr.join(''));
}
console.log(decodedValue(['brown', 'black']));