Trying to extend Electron app.
import { app } from "electron"
app.foo = "bar" // Property 'foo' does not exist on type 'App'.ts(2339)
Above works if I use //@ts-ignore
.
Trying to setup a .d.ts
override but what I came up with doesn’t work (just getting started with overrides).
electron.d.ts
import { App as ElectronApp } from "electron"
declare module Electron {
export interface App extends ElectronApp {
inspect: boolean
}
}
CodePudding user response:
Declaration merging is what I was looking for.
electron.d.ts
declare namespace Electron {
export interface App {
inspect: boolean
}
}
CodePudding user response:
You can import app
under a private name and then typecast it internally to be whatever you like.
import { app as _app } from "electron"
interface MyCustomProperties {
foo: string;
}
const app = _app as (typeof _app & MyCustomProperties);
app.foo = "bar";