Coder Social home page Coder Social logo

Dependency to @types/node makes electron package incompatible with typescript projects not using commonjs about electron-prebuilt HOT 11 CLOSED

tothdavid avatar tothdavid commented on August 11, 2024
Dependency to @types/node makes electron package incompatible with typescript projects not using commonjs

from electron-prebuilt.

Comments (11)

MarshallOfSound avatar MarshallOfSound commented on August 11, 2024

@zeke Hm, this is one we didn't think of 🤔

I mean, technically the typings are accurate but the AMD definitions override the built in require function, maybe this is something that can be fixed in the AMD typings (somehow overriding the nodejs require declaration)

from electron-prebuilt.

tothdavid avatar tothdavid commented on August 11, 2024

That's not actually the case: the Typescript compiler can't actually suppose you are using nodejs so there is actually no built in require function. That's why you need typings if you want to use the require function which is defined in e.g. @types/nodes or ˛@types/requirejs, but obviously they are not compatible so installing both packages will result in build error.

from electron-prebuilt.

MarshallOfSound avatar MarshallOfSound commented on August 11, 2024

@tothdavid The thing is Electron has all Node.JS API's (including require) built in, this is what I meant by the built in require function. If @types/requirejs needs to override that require I'm not sure how we can facilitate that or if it's something that needs to be fixed in those typings

from electron-prebuilt.

tothdavid avatar tothdavid commented on August 11, 2024

Sure, that's perfectly fine that you have electron building on node.js, but why do you expose @types/node as a dependency when you don't even have any other .ts/d.ts in your package? Why is it not only a devDependency?

The thing I am telling you is that the @types/requirejs typings are not wrong, they are just different as commonjs is not really a valid option when your code runs in a browser. Also as I mentioned above using electron for running unit tests are a pretty common use case for any projects not just for the ones targeting node.js.

from electron-prebuilt.

MarshallOfSound avatar MarshallOfSound commented on August 11, 2024

why do you expose @types/node as a dependency when you don't even have any other .ts/d.ts in your package

We do? Check an install of electron, it will contain an electron typings file (only the more recent versions of electron have this file).

Also the latest version of this typings file is in the repo at the moment

https://github.com/electron-userland/electron-prebuilt/blob/master/electron.d.ts

The thing I am telling you is that the @types/requirejs typings are not wrong

I'm not saying they are, just saying there must be some way to resolve a conflict between two type declarations 😄

from electron-prebuilt.

tothdavid avatar tothdavid commented on August 11, 2024

Oh, sorry, I checked the wrong version. :( But I can see it now.

You could still separate the typings from the main npm package and push the typings to a @types scoped package, but even typescript's recommendation is to publish them together:
https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html

Unfortunately require is a special function as it needs to be globally defined so there is not really a way (or at least none that I know of) to make both of them work in a single context.

from electron-prebuilt.

kenshyx avatar kenshyx commented on August 11, 2024

Why not using this https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/electron/index.d.ts ?

from electron-prebuilt.

MarshallOfSound avatar MarshallOfSound commented on August 11, 2024

@kenshyx That type definition file is community maintained and published to the @types scope, we now publish our own first-party typings file generated at build time from our docs and ship it with the electron module.

from electron-prebuilt.

kenshyx avatar kenshyx commented on August 11, 2024

Yeah, but it's a good base to use, right now that module will become unusable because they clash.

from electron-prebuilt.

MarshallOfSound avatar MarshallOfSound commented on August 11, 2024

@kenshyx First party typings are supposed to supersede the definitely typed modules. In the near future, the @types/electron package will probably be deprecated as people shouldn't be using both. They will just naturally get typings from the electron package.

from electron-prebuilt.

zeke avatar zeke commented on August 11, 2024

The electron-prebuilt repo is being retired and its code has been moved into the electron/electron repo. For the sake of historical transparency, we will leave GitHub Issues enabled on this repository, but if you are still affected by the issue reported here, please open a new issue on electron/electron repo and reference this issue from it so people can get the full context. The electron repository has a large and active contributor community, so your issue is more likely to get the attention it deserves there. Thanks!

For this issue specifically, https://github.com/electron/electron-typescript-definitions might be the most appropriate place to continue the discussion.

from electron-prebuilt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.