【问题标题】:How to add custom typed properties to Electron app?如何将自定义类型的属性添加到 Electron 应用程序?
【发布时间】:2023-01-26 03:43:12
【问题描述】:
import { app } from "electron"

app.foo = "bar" // Property 'foo' does not exist on type 'App'.ts(2339)

如果我使用//@ts-ignore,以上工作。

【问题讨论】:

    标签: typescript electron


    【解决方案1】:

    您可以在私有名称下导入 app,然后在内部将其类型转换为您喜欢的任何名称。

    import { app as _app } from "electron"
    
    interface MyCustomProperties {
      foo: string;
    }
    
    const app = _app as (typeof _app & MyCustomProperties);
    app.foo = "bar";
    

    【讨论】:

    • 感谢您的帮助……可以使用 .d.ts 文件来实现吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    • 2010-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多