Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add main type declarations #36

Merged
merged 1 commit into from
Mar 18, 2021
Merged

fix: Add main type declarations #36

merged 1 commit into from
Mar 18, 2021

Conversation

ffflorian
Copy link
Contributor

@ffflorian ffflorian commented Feb 12, 2021

I noticed that the file defined in main in the package.json file doesn't have type declarations since it is written in JavaScript.
This fix might help with #35.

export declare var require: NodeRequire;

// Taken from `RemoteMainInterface`
export {app, autoUpdater, BrowserView, BrowserWindow, ClientRequest, clipboard, CommandLine, contentTracing, Cookies, crashReporter, Debugger, desktopCapturer, dialog, Dock, DownloadItem, globalShortcut, inAppPurchase, IncomingMessage, ipcMain, Menu, MenuItem, MessageChannelMain, MessagePortMain, nativeImage, nativeTheme, net, netLog, Notification, powerMonitor, powerSaveBlocker, protocol, screen, ServiceWorkers, session, shell, systemPreferences, TouchBar, TouchBarButton, TouchBarColorPicker, TouchBarGroup, TouchBarLabel, TouchBarOtherItemsProxy, TouchBarPopover, TouchBarScrubber, TouchBarSegmentedControl, TouchBarSlider, TouchBarSpacer, Tray, webContents, WebRequest} from 'electron';
Copy link
Contributor Author

@ffflorian ffflorian Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this since it might not be exported anymore in the next version of Electron.

@jackple
Copy link

jackple commented Mar 18, 2021

Is there a plan to merge?

@ffflorian
Copy link
Contributor Author

Ping @miniak @MarshallOfSound

@miniak miniak requested a review from nornagon March 18, 2021 07:46
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the delay, this got lost in my inbox. I'm not super familiar with how .d.ts files work but if this works then I'm happy to merge it.

@nornagon nornagon merged commit 06280aa into electron:master Mar 18, 2021
@ffflorian ffflorian deleted the fix/main-declaration branch March 18, 2021 21:45
@zhoutwo
Copy link

zhoutwo commented Mar 26, 2021

Hi, when is this expected to be included in the next release? Currently, I'm poly-filling with

declare module '@electron/remote' {
  import { remote } from 'electron';
  export = remote;
}

I would love to use a more accurate type definition in my project.

@nornagon
Copy link
Member

It looks like the tests are failing on main: https://app.circleci.com/pipelines/github/electron/remote/117/workflows/8de10615-98d8-4bb5-9baa-0d69e50c5a2d/jobs/197

It seems related to this PR. Any ideas?

@ffflorian
Copy link
Contributor Author

It looks like the tests are failing on main: https://app.circleci.com/pipelines/github/electron/remote/117/workflows/8de10615-98d8-4bb5-9baa-0d69e50c5a2d/jobs/197

It seems related to this PR. Any ideas?

I'll check

@ffflorian
Copy link
Contributor Author

@nornagon See #48

@electron-bot
Copy link

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@zhoutwo
Copy link

zhoutwo commented Apr 25, 2021

I'm getting the following errors in v1.1.0:

TS2304: Cannot find name 'NodeRequireCache'.
TS2304: Cannot find name 'NodeExtensions'.

It seems NodeRequireCache and NodeExtensions are not in @types/node for some reason. Is it okay if I just create a PR that copies from DefinitelyTyped?

interface NodeRequireCache {
    [path: string]: NodeModule;
}
interface NodeExtensions {
    '.js': (m: NodeModule, filename: string) => any;
    '.json': (m: NodeModule, filename: string) => any;
    '.node': (m: NodeModule, filename: string) => any;
    [ext: string]: (m: NodeModule, filename: string) => any;
}

This should be alright because of the declaration merging feature in TypeScript.

@ffflorian
Copy link
Contributor Author

Is it okay if I just create a PR that copies from DefinitelyTyped?

Yes, sure! I did the same.

@john8329
Copy link

john8329 commented May 17, 2021

This problem (NodeRequireCache) happens here too. Odd thing is that the types are there and the node types are updated to v14.14.45. I'll have to revert to the deprecated module until this is solved.

EDIT:
Two minutes of thinking and searching led me to this workaround: add the electron types in tsconfig.json before the standard node ones. For some reason Electron 11 has them but node 14 doesn't.

"typeRoots": [
      "node_modules/electron/node_modules/@types",
      "node_modules/@types",
    ]

@ffflorian
Copy link
Contributor Author

Please see #58.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants