Typescript error: TS7053 Element implicitly has an 'any' type

后端 未结 2 1507
走了就别回头了
走了就别回头了 2020-12-10 00:27

this is part of my code:

const myObj: object = {}
const propname = \'propname\'

myObj[propname] = \'string\'
<         


        
相关标签:
2条回答
  • 2020-12-10 01:02

    You have to define what kind of index type the object has. In your case it is a string based index.

    const myObj: {[index: string]:any} = {}
    
    0 讨论(0)
  • 2020-12-10 01:18

    Why just simple replace 'object' with 'any':

    const myObj: any = {}
    const propname = 'propname'
    
    myObj[propname] = 'string'
    

    Another short alternative.

    0 讨论(0)
提交回复
热议问题