phetsims / sun

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

GroupItemOptions and ToggleNode should know what subtype of Node they are creating #846

Closed samreid closed 1 year ago

samreid commented 1 year ago

For https://github.com/phetsims/center-and-variability/issues/170, it would be helpful for GroupItemOptions and ToggleNode to know what subtype of Node they are creating.

samreid commented 1 year ago

@zepumph can you please help review this issue? See also TODOs in https://github.com/phetsims/center-and-variability/issues/201 where type inference isn't working as expected. This issue is related to iteration item https://github.com/orgs/phetsims/projects/65?pane=issue&itemId=27371596 which is priority 10.1 overall.

zepumph commented 1 year ago

We got rid of the defaults and type inference is working well when each createNode creates the same type.

When having the heterogenous elements list like in VariabilityPlotNode, we found https://github.com/microsoft/TypeScript/issues/33664 and https://github.com/microsoft/TypeScript/issues/31617#issuecomment-496581018 and as a result are happy to chock this up to a weirdness of TypeScript lazily inferring the first generic. Typescript has done this by design, and they aren't changing.

We are ready to close and are fine specifying things manually when needing a Supertype for a heterogenous array of elements.