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

add types for suffixed properties, paddingX, etc #50

Merged
merged 1 commit into from
Dec 28, 2022
Merged

Conversation

ChristopherChudzicki
Copy link
Collaborator

@ChristopherChudzicki ChristopherChudzicki commented Dec 28, 2022

This PR adds types for more of the node properties. I think I have them all now.

Background: traits and properties

Mathbox nodes get their properties from "traits". For example, <grid /> has the following 16 traits:

export class Grid extends Primitive {
  static initClass() {
    this.traits = [
      "node",
      "object",
      "visible",
      "style",
      "line",
      "grid",
      "area",
      "position",
      "origin",
      "shade",
      "axis:x",
      "axis:y",
      "scale:x",
      "scale:y",
      "span:x",
      "span:y",
    ];
  /** rest of class */
}

Each trait defines a bunch of properties. For example, the axis trait defines two properties:

  axis: {
    detail: Types.int(1),
    crossed: Types.bool(false),
  },

Aliasing

When Grid includes "axis:x" and axis:y" as traits, the axis properties get included twice with suffixes X and Y:

// Grid Properties
{
  detailX: number
  crossedX: boolean
  detailY: number
  crossedY: boolean
}

Previous work

When I originally added Typescript definitions for mathbox (0665621) I did not understand how the above suffix aliasing worked, so I just skipped those properties. Consequently, <grid> and a bunch of other node types were missing a bunch of properties. This PR adds them in.

* Create a type with the same keys as `R` but with the suffix `S` appended.
* Keys of `R` that are not strings are ignored.
*/
type Suffixed<R, S extends string> = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependent types??

@@ -2459,7 +2467,11 @@ export interface AreaPropsNormalized
GetTraitsData,
GetTraitsMatrix,
GetTraitsTexture,
GetTraitsArea {
GetTraitsArea,
Suffixed<GetTraitsSpan, "X">,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! didn't know typescript had these.

@sritchie sritchie merged commit 454f239 into master Dec 28, 2022
@sritchie sritchie deleted the more-types branch December 28, 2022 17:31
@sritchie
Copy link
Collaborator

The writeup here is great too. We need to collect these research notes into better docs for the whole project at some pt as well

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

Successfully merging this pull request may close these issues.

2 participants