phetsims / sun

User-interface components for PhET simulations, built on top of Scenery.
MIT License
4 stars 12 forks source link

Review conversion of ClosestDragListener to TypeScript #756

Closed pixelzoom closed 2 years ago

pixelzoom commented 2 years ago

@jonathanolson please review the TypeScript conversion of ClosestDragListener in https://github.com/phetsims/sun/commit/4a3affd5f709bb68a888fa3cdedfe3956127cd47.

You had {SceneryEvent} event specified as the event type. That caused problems with the type-checker in both number-play and counting common:

TS2345: Argument of type 'PaperNumberNode' is not assignable to parameter of type 'DraggableItem'. Types of property 'startDrag' are incompatible. Type '(event: PressListenerEvent) => void' is not assignable to type '(event: SceneryEvent) => void'.        Types of parameters 'event' and 'event' are incompatible. Type 'SceneryEvent' is not assignable to type 'PressListenerEvent'. Type 'Event' is not assignable to type 'PressListenerDOMEvent'. Type 'Event' is missing the following properties from type 'KeyboardEvent': altKey, charCode, code, ctrlKey, and 17 more

I had to change to event: PressListenerEvent.

jonathanolson commented 2 years ago

That sounds good (conversion looks good). If we need more flexibility, ClosestDragListener could take a type parameter (but PressListenerEvent should work for our drag handlers).

pixelzoom commented 2 years ago

👍🏻