How to get around property does not exist on 'Object'

后端 未结 2 477
梦谈多话
梦谈多话 2020-12-05 09:36

I\'m new to Typescript, and not sure how to word this question.

I need to access two \"possible\" properties on an object that is passed in the constructor. I know

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 10:08

    If you don't want to change the type or create an interface, you can also use this syntax to access unknown properties:

    selector ():string {
        return this.options["selector"];
    }   
    
    template ():string {
        return this.options["template"];
    }
    

提交回复
热议问题