phetsims / axon

Axon provides powerful and concise models for interactive simulations, based on observable Properties and related patterns.
MIT License
10 stars 8 forks source link

Review the in/out covariant/contravariant type parameter annotations #389

Closed samreid closed 1 year ago

samreid commented 2 years ago

In #370, we designed the Property interfaces to support covariant usages and I think that issue is at a good point. TypeScript 4.7 Beta introduced a new feature that overlaps with that somewhat:

Optional Variance Annotations for Type Parameters https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#optional-variance-annotations-for-type-parameters

It allows you to specify in and/or out annotations on type parameters. I thought I would bring it to our attention in case it informs #370 or other covariant/contravariant discussions. Tagging @pixelzoom and @jonathanolson so they are aware. Not really sure what would have to happen for this issue to be closed. Perhaps review/understand the new annotations and determine where they are appropriate to use in our codebase?

pixelzoom commented 2 years ago

Thanks, I read the reference. Variance annotations sounds like a feature to be used judiciously. It also isn't clear to me whether TS will prevent you from (for example) using the in annotation for something that is actually used as an output. (And I didn't have time or inclination to experiment.)

samreid commented 1 year ago

We applied a usage of this (incorrectly) in Joist as part of https://github.com/phetsims/joist/issues/783 and had some discussion as a team. Any more effort here can be done on-demand in the future when necessary. Closing.