How to handle warnings for proprietary/custom properties of built-in objects in TypeScript

前端 未结 2 2031
猫巷女王i
猫巷女王i 2020-12-06 04:30

I am using Personas which relies on the proprietary property navigator.id. Since this property is not standard, the TypeScript compiler generates the following warning:

相关标签:
2条回答
  • 2020-12-06 04:35

    Add checks like if(navigator.id != null && typeof navigator.id != 'undefined') before stmt where navigator.id is referred

    0 讨论(0)
  • 2020-12-06 04:41

    1) You can reinterpret navigator prop.

    (<any>navigator).id.request();
    

    2) You can declare id prop youself

    mycompany.lib.d.ts

    interface Navigator {
      id: any
    }
    

    app.ts

    navigator.id.request();
    

    see this video http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript/ There Anders tell as jQuery.UI add new methods to jQuery (see 46 min)

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