-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Breaks with @types/node@18.8.5, Type '...' is not assignable to type 'Event'. ts2322 #6899
Labels
Comments
7 tasks
Also opened an issue in DT repo DefinitelyTyped/DefinitelyTyped#62759 |
Related PR #6855 |
Comment by sodatea in the PR: 15 hours ago
|
yyx990803
pushed a commit
that referenced
this issue
Nov 8, 2022
chrislone
pushed a commit
to chrislone/core
that referenced
this issue
Feb 4, 2023
zhangzhonghe
pushed a commit
to zhangzhonghe/core
that referenced
this issue
Apr 12, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Vue version
(Not related)
Link to minimal reproduction
https://www.typescriptlang.org/play?jsx=1#code/JYWwDg9gTgLgBAbwL5wGZQiOByAbgVwFNsAoAejLgAEYBnAWkIA8xCBjGRqDKOAG0LwwfAIYBPAOYZ8AOwAmcYDNowRfPtRhjWtMjIhzCJUJFhwtrRCnSYc+w6RJsIy+ABU4AXjgAeOcFw4FwBhPmA2AGtPBAAKAEovAD4rFDJEkiA
Steps to reproduce
Make sure to have
vue
and@types/node
installed.What is expected?
No type error
What is actually happening?
Type '() => void' is not assignable to type 'MouseEvent'. (2322)
System Info
Any additional comments?
This is caused by DefinitelyTyped/DefinitelyTyped#59905.
Vue uses the following code to get generate the signature of event handlers:
core/packages/runtime-dom/types/jsx.d.ts
Lines 1303 to 1305 in 9617dd4
And Vue maintains an event map. It tests each property is assignable to Function (interface).
On the other side, @types/node introduces a new change to include browser types that are implemented in Node, which is, unfortunately, incompatible with DOM.
The PR is intended to not re-declaring the existing type (from libdom) if possible (which is not possible in TypeScript), but they're doing it in the wrong way.
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/c52afba497870de8fe73942dc605081576f149e0/types/node/dom-events.d.ts#L107
It augmented the global Event interface with
__Event
And
__Event
is defined in the following way:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/c52afba497870de8fe73942dc605081576f149e0/types/node/dom-events.d.ts#L11
It tries to reuse the global
Event
value (which is NOT the global interfaceEvent
), which means__Event
is the constructor of DOM Events.Because (AFAIK) it is impossible to "reflect" a type out to solve this problem.
This brings us back to the Vue side.
With the augmented global
Event
interface, now all DOM events (MouseEvent
,KeyboardEvent
, etc) are now inherited from the global Event constructor (from the value namespace).And
E[K]
(Events) now all passes theextends Function
test and makes all DOM JSX types broken (they're now typed asonClick?: MouseEvent | undefined
).The text was updated successfully, but these errors were encountered: