samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.73k stars 69 forks source link

EventEmitter intellisense/type safety #163

Closed saantonandre closed 1 month ago

saantonandre commented 1 month ago

The current type declaration does not provide intellisense to the EventEmitter methods of Window: image

Which is quite annoying because the only way to know the parameter for a specific event would be to log them beforehand. Through some logging and typescript gymnastic I've created a mapped type for every suppoerted event, so that the EventEmitter methods will suggest the event types and correctly infer the respective callbacks arguments: Screenshot 2024-10-21 020634 Screenshot 2024-10-21 020737 Screenshot 2024-10-21 020611

samizdatco commented 1 month ago

Really nice work! Thanks so much for digging through all the event types to collect this. I had to bump the @types/node version to pick up an updated EventEmitter def that takes the events map as a generic but otherwise this seems good to go.