Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to typescript #306

Open
zepumph opened this issue Oct 26, 2022 · 5 comments
Open

Convert to typescript #306

zepumph opened this issue Oct 26, 2022 · 5 comments
Assignees

Comments

@zepumph
Copy link
Member

zepumph commented Oct 26, 2022

Wahoo!

@zepumph
Copy link
Member Author

zepumph commented Oct 26, 2022

Please note https://github.com/phetsims/phet-info/blob/master/doc/typescript-conventions.md#L19. And we should probably go through the options and enums patterns together.

@zepumph
Copy link
Member Author

zepumph commented Dec 12, 2022

After discussing with @matthew-blackman, I decided to convert a single model/view pair as reference. Here are some notes about my conversion:

  • Note how I "widen" the public api of Properties whenever possible to the most general item. I only need to listen to the zoomProperty so it is a TReadOnlyProperty. positionProperty is a Property instead of TProperty because it needs a reset method.
  • phetioDocumentation passed to DragListener wasn't doing anything (yay typescript for the bug fix)
  • getJustDataProbeBounds didn't have the return type annotated.
  • Take a look at the optionize pattern in DataProbeNode, that uses the ParentOptions pattern we discussed all to briefly this morning.

I'm excited to discuss further!

zepumph added a commit that referenced this issue Dec 12, 2022
zepumph added a commit that referenced this issue Dec 12, 2022
matthew-blackman pushed a commit that referenced this issue Dec 13, 2022
matthew-blackman pushed a commit that referenced this issue Dec 13, 2022
matthew-blackman pushed a commit that referenced this issue Dec 14, 2022
matthew-blackman pushed a commit that referenced this issue Dec 14, 2022
matthew-blackman pushed a commit that referenced this issue Dec 14, 2022
matthew-blackman pushed a commit that referenced this issue Dec 14, 2022
matthew-blackman pushed a commit that referenced this issue Dec 14, 2022
matthew-blackman pushed a commit that referenced this issue Dec 14, 2022
@matthew-blackman
Copy link
Contributor

The common model/view is fully converted, so I think this may be a good time for a code review before the final conversion push @zepumph

matthew-blackman pushed a commit that referenced this issue Dec 20, 2022
matthew-blackman pushed a commit that referenced this issue Dec 20, 2022
zepumph added a commit that referenced this issue Jan 5, 2023
zepumph added a commit that referenced this issue Jan 5, 2023
zepumph added a commit that referenced this issue Jan 5, 2023
zepumph added a commit that referenced this issue Jan 5, 2023
@zepumph
Copy link
Member Author

zepumph commented Jan 6, 2023

Overall things are looking really really good. Thanks for all the hard work here, it is really helping me to understand the sim code.

  • Vector2Property is an implementation detail, and I recommend using a more general type that isn't so closely tied to a specific class for the Type:
    public readonly basePositionProperty: Vector2Property;
    public readonly tipPositionProperty: Vector2Property;
  • * {ProjectileObjectType} defaultProjectileObjectType - default object type for the model
    * {boolean} defaultAirResistanceOn - default air resistance on value
    * {ProjectileObjectType[]} possibleObjectTypes - a list of the possible ProjectileObjectTypes for the model
    * {Tandem} tandem
    * options
    */
    and
    * {number} numProjectiles - the number of simultaneous projectiles to fire
    and
    * {ProjectileObjectType} selectedProjectileObjectType - contains information such as mass, diameter, etc.
    and probably others still has jsdoc type info in it and shouldn't. Perhaps a search for * { will help find the rest.
  • Most likely all usages of providedOptions: should be providedOptions?:, but I'll let you confirm for each case.
  • public readonly positionProperty: NumberProperty;
    doesn't need to be a NumberProperty as I don't see range used anywhere.
  • TrajectoryOptions duplicates parent options, and should instead use an empty selfOptions and call upon PhetioObjectOptions
  • why is this a templated var that resolves a multiline single quote string?
    phetioDocumentation: `${
    'The count of how old this projectile trajectory is. Older trajectories have more ' +
    'opacity until they are subsequently removed. The most recent trajectory fired has rank 0. ' +
    'The second most recent has rank 1.'
    }`,
  • Usages of merge should instead by combineOptions to keep type safety.
  • BackgroundNodeOptions defines pickable, but that is a NodeOption, so we can use EmptySelfOptions here.
  • private flatirons: Image;
    this could be defined as a Node, because it is only used as such, that makes for a more stable API if in the future you wanted to change that from an Image to something else.
  • There are many many spots where readonly is not used and should be. For example
    private sky: Rectangle;
    private grass: Rectangle;
    private road: Rectangle;
    private roadDashedLine: Line;
    private flatirons: Image;
    .
  • CannonNodeOptions defines tandem and renderer which are both parent options, let's not put those in SelfOptions also.
  • FireButton.baseColor is a parent option.
  • Something that may be good to try is to batch rename public to private in the whole repo and see how many errors you get. That may help find spots where you missed a private thing. Note though that it is possible to find something with no usages publicly that you still want to be public, but most often that happens in common code, and not sim-specific stuff.
  • ProjectileMotionScreenViewOptions.tandem is a parent option
  • These need to be marked as optional to get the benefits of optionize,
    type ProjectileMotionViewPropertiesOptions = {
    tandem: Tandem;
    forceProperties: boolean;
    accelerationProperties: boolean;
    };
  • Note that ProjectileMotionViewProperties.tandem is NOT a parent option, good work defining it!
  • ProjectileNodeOptions.preventFit is a parent option
  • Note that even static members of ProjectileObjectViewFactory should be marked as readonly
  • many options in ToolboxPanelOptions are from parent options
  • We want to make a new issue to convert VectorsDisplayEnumeration to use the new Enumeration pattern
  • I have already said this, but there are many spots where you have optional options with defaults, but the type doesn't have a question mark on it. That is not idea, even if all usages pass in a value for that, if there is a reasonable default, it should be marked as optional. Please look at this link and scan everywhere for the issue:
    export type ProjectileMotionUIOptions = {
    controlsVerticalSpace: number;
    xSpacing: number;
    textDisplayWidth: number;
    numberDisplayMaxWidth: number;
    textDisplayHeight: number;
    readoutXMargin: number;
    sliderLabelSpacing: number;
    } & PanelOptions;
  • I think a couple more usages of satisfies would be nice in ProjectileMotionConstants when it is clearly an options block for a particular type's options.

UPDATE: 1/11/23

  • Please see CT required tandems must be supplied #319 for some work in tightening up ScreenView classes, each should require a tandem, and so we should be thoughtful about that when converting to typescript. Let's make sure each of those options types require a tandem (using PickRequired if needed).

Thanks for all the good work. I definitely went fast and could have missed some stuff. I'd say stay diligent as you go through these items and feel free to convert the rest. I also think we likely want another issue to try to tease out the options type where we were mixing things in ProjectileMotionUIOptions. Likely a separate issue, and I believe you will run into that much much more in the specific screen code. Thanks!

@zepumph zepumph removed their assignment Jan 6, 2023
zepumph added a commit that referenced this issue Jan 6, 2023
@samreid
Copy link
Member

samreid commented Feb 10, 2023

@matthew-blackman has said the conversion to TypeScript is partway done, and I see lots of great review recommendations above. Also, this sim is in a sprint team for this sprint, so I think will get appropriate attention. Thus, removing the ready-for-review label for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants