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

前端 未结 2 2034
猫巷女王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:41

    1) You can reinterpret navigator prop.

    (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)

提交回复
热议问题