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.
It tries to reuse the global Eventvalue (which is NOT the global interface Event), which means __Event is the constructor of DOM Events.
Because (AFAIK) it is impossible to "reflect" a type out to solve this problem.
// Note: globalThis is a namespacenamespaceTest{exportinterfaceName{value: 1}exportvarName: Function&{value: 2}}type_=[Test.Name['value'],// 1typeofTest.Name['value'],// 2typeofTestextends{Name: infer N} ? N : never// Function & { value: 2 }]
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).
Jack-Works
changed the title
TypeScript incompatibility with @types/node@18.8.5
Breaks with @types/node@18.8.5, Type '...' is not assignable to type 'Event'. ts2322
Oct 17, 2022
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: