-
Notifications
You must be signed in to change notification settings - Fork 15k
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
electron.d.ts does not work with @types/node v13.1.0 #21612
Comments
I believe we can no longer use |
The Cannot extend an interface 'NodeJS.EventEmitter'. Did you mean 'implements'? More |
Yeah, the message is caused by the above compile error. And |
* feat(node): v13 * feat(node): v13.2
Running into same issue |
It's expected as Electron v7 comes with node v12, so use the most recent @types/node v12. |
No @vladimiry . That's not how it works - there is no direct tie between Electron incompatibility with the latest |
Can you provide a source? |
Even if I can't (which I'm sure I could if I spent the time), the problem is most solutions reference many packages that reference @types/node via a version range. The problem is electron types declare a class |
At least Electron v8 beta and v9 nightly have the same issue. Is there any plan to fix this incompatibility between |
Electron 8.0.0-beta.5 comes with Node 12.13.0, didn't try the 9-nightly build. |
My point is whether the incompatibility is recognized by team and tracked anywhere for fix until node v13 upgrade. |
Is there a temporary workaround to this? I'm unable to compile a typescript project due to the error listed in OP. |
Force all references in your package.json and yarn.lock to use @types/node
12.21.12. This is an unacceptable but hopefully temporary scenario
There's a few people trying to act as though the problem is electron 7 uses
node 12 and not 13. They're just plain wrong. The problem is the use of
extends vs implements keywords on classes/interfaces. Again you have
version ranges (for example, redux says @types/node:^8)
…On Wed, Dec 25, 2019, 8:33 AM Cyrus Frost ***@***.***> wrote:
Is there a temporary workaround to this? I'm unable to compile a
typescript project due to the error listed in OP.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#21612?email_source=notifications&email_token=AAQGPCWYY4R2NEQ6OW23OYLQ2NOJLA5CNFSM4J63DZ52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHULURI#issuecomment-568900165>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQGPCTIGMVJ4QSYKYF7TKTQ2NOJLANCNFSM4J63DZ5Q>
.
|
This workaround works! Thanks! Minor correction: the |
Looks like we got thoughtful TypeSript and semver versioning expert here ==> @amirburbea
Electron npm module is shipped with @types/node@^12.0.12 at the moment so it's totally fine that they do
Electron even has automated test added for verifying that major versions of bundled node and @types/node got matched, see https://github.com/electron/electron/blob/f426ad1b5914295f9684036fb55f918c1b074900/spec-main/types-spec.ts
For curious persons, checking @types/node and nodejs versions correlation:
You can clone the https://github.com/DefinitelyTyped/DefinitelyTyped and execute c47a34ead1637f6f34e7d630dc88ea3f6e5562cb feat(node): v13 (#40927)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 12.12
+// Type definitions for non-npm package Node.js 13.1
a91a9a49ded5dd536a4bb0d2098eb1b0de1eadcd feat(node): v12.12 (#39914)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 12.11
+// Type definitions for non-npm package Node.js 12.12
cbe21d594a3b24fd1b93719958bc90ab6007ac51 feat(node): v12.11 (#39116)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 12.7
+// Type definitions for non-npm package Node.js 12.11
3f6627ea70b804317b90c0212b2055eff0a67a6f feat(node): v12.7 (#37217)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 12.6
+// Type definitions for non-npm package Node.js 12.7
4db4c26549c7edd452c46492f3421d5dce3200b0 feat: node v12.5 (#36562)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 12.0
+// Type definitions for non-npm package Node.js 12.6
18b13d1f4a6830861bf4f693a706dcde4aa8b21f feat(node): v12 (#34952)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 11.13
+// Type definitions for non-npm package Node.js 12.0
e6625ba155c7529e8bfb751a23b0d12bb8fe1ec5 feat(node): v11.13
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 11.12
+// Type definitions for non-npm package Node.js 11.13
923fe86451333613c015358a7447ed914945427f feat(node): v11.12 (#33967)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 11.11
+// Type definitions for non-npm package Node.js 11.12
bac137341280d31ee0f8159ddad66b0fa144e5fa feat(node): v11.11
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 11.10
+// Type definitions for non-npm package Node.js 11.11
80fb3119f40c6b70e4a9632887980036e36f6b2b feat(node): v11.10
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for non-npm package Node.js 11.9
+// Type definitions for non-npm package Node.js 11.10
608c146d8982a2ff7307f0a3bdddd6d55cb1a63e Mark non-npm packages
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for Node.js 11.9
+// Type definitions for non-npm package Node.js 11.9
c8dadc971b8524704c4b39243780e294d7a15f12 feat(node): enable strict null checks and add SharedArrayBuffer
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for Node.js 11.6
+// Type definitions for Node.js 11.9
e69abd8af13b4dd17259e72898b118102993915d feat(node): v11.6
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for Node.js 10.12
+// Type definitions for Node.js 11.6
df80e09009547e5556c09a16f3c715ecf9aff325 feat(node): 10.12 (#29689)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for Node.js 10.11
+// Type definitions for Node.js 10.12
352f2a6a39758bead6182a0d04bcf0b8d7c7a381 chore(node): apply lint
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for Node.js 10.11.x
+// Type definitions for Node.js 10.11
e17d39e6b09a1e44d7dd69fa22b3da42c7156948 feat(node): 10.11
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for Node.js 10.10.x
+// Type definitions for Node.js 10.11.x
9061b19a3c7d676fc4aeacc825ab7790edad13c6 types(node): add changes from 10.10 (#28918)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for Node.js 10.9.x
+// Type definitions for Node.js 10.10.x
374598de675780b1312912d43dff88f9fbfcf0d8 [node] Add http[s] request/get variants for 10.9.0 (#28193)
diff --git a/types/node/index.d.ts b/types/node/index.d.ts
--- a/types/node/index.d.ts
+++ b/types/node/index.d.ts
@@ -1,1 +1,1 @@
-// Type definitions for Node.js 10.7.x
+// Type definitions for Node.js 10.9.x
3c8f15080c5728847c627ba07a623276ef1869ab add timeout to http.AgentOptions (#21346
... Regarding @types/node v13. You could see that what they do there with like 160 d.ts files of different libraries to make them compatible with @types/node@^13 is replacing
with
So @electron will probably follow the same way one day when they move to @types/node@^13. |
I believe replacing I concern this because it requires many changes in |
From the DefinitelyTyped side, I’ve confirmed this was a correct change. The typings previously allowed this: new NodeJS.EventEmitter(); which of course does not exist at runtime.
Sort of—the deal is that when you have any
|
I think it's safe to assume if someone is using a recent version of |
That’s not really the issue—the decision for electron to make is whether they need to support anyone with TS 2.8 or earlier, because they’re presumably only going to ship the same electron.d.ts to everyone. They can’t ship the new syntax conditionally upon whether the user has a recent |
I think it's safe to move to 3.0 as a baseline for electron's use of typescript. That would be 18 months old already. (TS3.0 released July2018, TS 2.8 was March2018 - not even a huge lag time between them) |
I have no real opinion on how this should be dealt with, but as the person who merged the PR that caused this issue, I just wanted to
|
|
I did not know that the dynamic import syntax is available in ambient context. Thank you for letting me know! Yeah, |
I had an experiment that adds
|
What about `class BrowserWindow extends import('events').EventEmitter`
…On Tue, Dec 31, 2019, 8:41 AM Linda_pp ***@***.***> wrote:
I had an experiment that adds type EventEmitter =
import('events').EventEmitter; in namespace Electron { ... } block and
removes NodeJS. from class BrowserWindow extends NodeJS.EventEmitter.
However, I got following error. I think type EventEmitter = ... only
imports type but extends requires value so it is unavailable here.
node_modules/electron/electron.d.ts:1657:31 - error TS2693: 'EventEmitter' only refers to a type, but is being used as a value here.
1657 class BrowserWindow extends EventEmitter {
~~~~~~~~~~~~
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#21612?email_source=notifications&email_token=AAQGPCWQTNSCLNGH77BAGJ3Q3NDYZA5CNFSM4J63DZ52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH4HFZI#issuecomment-569930469>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQGPCQEYHIK4RAH7C5PBBTQ3NDYZANCNFSM4J63DZ5Q>
.
|
It does not work because |
Where is the
|
You need to first import events (import events from 'events' or maybe const
events = require('events'))
…On Tue, Dec 31, 2019, 9:00 AM Linda_pp ***@***.***> wrote:
So yeah, replacing NodeJS.EventEmitter with events.EventEmitter is even
simpler, which @amirburbea <https://github.com/amirburbea> already
mentioned.
Where is the events global value defined? I simply replaced
NodeJS.EventEmitter with events.EventEmitter but got following error:
node_modules/electron/electron.d.ts:1655:31 - error TS2552: Cannot find name 'events'. Did you mean 'Event'?
1655 class BrowserWindow extends events.EventEmitter {
~~~~~~
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#21612?email_source=notifications&email_token=AAQGPCQI7Z7KPIVJG6ZN2UDQ3NF7JA5CNFSM4J63DZ52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH4HZWY#issuecomment-569933019>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQGPCWE4SZAMOWGPYMO7J3Q3NF7JANCNFSM4J63DZ5Q>
.
|
Yeah, so I think we need to choose the first option @andrewbranch showed. As I commented above, |
I still have this problem. I can't keep my @types/node to 12.12.21 for long time. |
I recommended before to open a new issue since in my experience closed issues don't get reopened here. |
…n/electron#21612 (comment)) Change format in main/index.ts
Anyway how to make it working? Having downgraded "@types/jest" to "25.1.4" is not long-term fix :(. Thank you. |
Right now only electron v10 is shipped with updated definitions (it uses @electron/typescript-definitions@^8.7.2). |
Run |
Of course it works this way. The point of this issue is that other deps used in the project require node@^13. |
Thank you @vladimiry, I've been following this thread for 4 or so months and every once in a while someone feels compelled to write how they got this to work by using @types/node 12 with some npm or yarn command. As you said, that's the point of this whole thread. |
same problem even with electron v9.0.0 |
guys this is closed issue and nobody will look at it. |
As it is said repeatedly in this issue thread, the fix for electron.d.ts for Node v13 is already there. I had made a PR and it was merged. But Node.js integrated to Electron is still v12 even in Electron v9. So using |
1674:31 Cannot extend an interface 'NodeJS.EventEmitter'. Did you mean 'implements'? 1672 | } 1673 | > 1674 | class BrowserWindow extends NodeJS.EventEmitter { use node 12 https://github.com/ikuokuo/start-electron/blob/master/docs/tutorial/5_electron-app.md why not use node > 12 electron/electron#21612
So I have the same problem trying to use fs in my Angular9/Electron9 desktop app, seems to me like the best workaround would be to require all the necessary classes (in my case electron.remote) in a preload.js instead of downgrading the node version just for a single module (electron)? |
upgrade to electron 10, problem solved! |
Preflight Checklist
Issue Details
Expected Behavior
Can compile successfully the TypeScript code
Actual Behavior
Compilation error
EDIT: Added entire compile error messages thanks to #21612 (comment)
To Reproduce
Try to compile following code with the latest TypeScript compiler and latest
@types/node
package.Package versions:
typescript
: 3.7.4@types/node
: 13.1.0Screenshots
Nothing
Additional Information
I have investigated this issue and found the cause.
@types/node
v13 has breaking change affectingNodeJS.EventEmitter
from v12. It was changed fromclass
tointerface
. Now,EventEmitter
can only be extended by interfaces. I confirmedelectron.d.ts
worked fine with@types/node
v12. The change is here:DefinitelyTyped/DefinitelyTyped@c47a34e#diff-a2f9a5377787f7084c7f52b20c0108cfR540
However, classes such as
BrowserWindow
inelectron.d.ts
try to extendEventEmitter
so it is causing this issue.May be related to #21475
The text was updated successfully, but these errors were encountered: