Element implicitly has an 'any' type because expression of type 'string' can't be used to index

后端 未结 9 1568
滥情空心
滥情空心 2020-11-27 15:42

Trying out TypeScript for a React project and I\'m stuck on this error:

Element implicitly has an \'any\' type because expression of type \'string\' can\'t b         


        
9条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 16:22

    When using Object.keys, the following works:

    Object.keys(this)
        .forEach(key => {
          console.log(this[key as keyof MyClass]);
        });
    

提交回复
热议问题