electron/remote

Release 2.0.5 fails to compile

k8stone opened this issue · 6 comments

Issue discover using a project that depends on an up-to-date Electron, currently 17.0.1. Three new lines in index.d.ts are the source of the problem:

line 42:
export var nativeImage: typeof Electron.NativeImage;

line 57:
export var webContents: typeof Electron.WebContents;

line 58:
export var webFrameMain: typeof Electron.WebFrameMain;

All three can be fixed by using the type of the exported instances rather than relying on types that aren't directly available outside the Electron package:

export var nativeImage: typeof Electron.nativeImage;
export var webContents: typeof Electron.webContents;
export var webFrameMain: typeof Electron.webFrameMain;

Same error, Electron 17.0.1

Same error Electron 17.0.1 @electron/remote 2.0.4 builds fine, 2.0.5 does not.

Error: Error: node_modules/@electron/remote/index.d.ts:42:41 - error TS2551: Property 'NativeImage' does not exist on type 'typeof CrossProcessExports'.
42 export var nativeImage: typeof Electron.NativeImage;

Error: Error: node_modules/@electron/remote/index.d.ts:57:41 - error TS2551: Property 'WebContents' does not exist on type 'typeof CrossProcessExports'.
57 export var webContents: typeof Electron.WebContents;

Error: Error: node_modules/@electron/remote/index.d.ts:58:42 - error TS2551: Property 'WebFrameMain' does not exist on type 'typeof CrossProcessExports'.
58 export var webFrameMain: typeof Electron.WebFrameMain;

FYI - It looks like these types are exported in Electron 17.1.0. It would still be nice to have a more flexible solution, but that's at least workable presuming 17.1.0 doesn't break anything significant.

cc @andersk looks like something went wrong with #108 and/or #109

Thanks for the ping. This seems to be a change between Electron 14 and 15. Electron 14 declares

declare namespace Electron {
  class NativeImage {  }
  class WebContents extends NodeEventEmitter {  }
  class WebFrameMain extends NodeEventEmitter {  }
  const nativeImage: typeof NativeImage;
  const webContents: typeof WebContents;
  const webFrameMain: typeof WebFrameMain;
}

declare module 'electron' {
  export = Electron;
}

where the difference between nativeImage: typeof NativeImage and native: NativeImage is that the former (correctly) prohibits access to non-static members.

But Electron 15 declares

declare namespace Electron {
  class NativeImage {  }
  class WebContents extends NodeEventEmitter {  }
  class WebFrameMain extends NodeEventEmitter {  }
  namespace CrossProcessExports {
    const nativeImage: typeof NativeImage;
    type NativeImage = Electron.NativeImage;
    const webContents: typeof WebContents;
    type WebContents = Electron.WebContents;
    const webFrameMain: typeof WebFrameMain;
    type WebFrameMain = Electron.WebFrameMain;
  }
}

declare module 'electron' {
  export = Electron.CrossProcessExports;
}

where NativeImage is only exported as a type alias, not a class, so typeof NativeImage can no longer be used from outside.

I think typeof Electron.nativeImage will do the right thing in both versions, so I opened #111 to switch to that.

🎉 This issue has been resolved in version 2.0.8 🎉

The release is available on:

Your semantic-release bot 📦🚀