【问题标题】:Is there a way to add typescript definintions to the "window" object [duplicate]有没有办法将打字稿定义添加到“窗口”对象[重复]
【发布时间】:2017-04-11 17:16:26
【问题描述】:

Visual Studio 为 window 对象内置了大部分 typescript 定义,因为它们中的大多数都可以工作。但是,“window.chrome”没有定义。如何将其添加到现有的打字稿定义中,以便让 Visual Studio 进行编译?

var isChromium = window.chrome;

【问题讨论】:

    标签: visual-studio typescript


    【解决方案1】:

    您可以在代码中的任何位置扩展Window 接口:

    interface Window {
        chrome:any; //you can go further and define a strict shape of this member
    }
    

    接口声明可以拆分为多个文件 - 编译器会将所有同名的接口声明合并到一个定义中。

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-31
    • 1970-01-01
    • 2011-06-05
    • 2021-11-05
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多