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

Improve union types of the modelling comands #142

Open
Irev-Dev opened this issue Aug 2, 2023 · 0 comments
Open

Improve union types of the modelling comands #142

Irev-Dev opened this issue Aug 2, 2023 · 0 comments

Comments

@Irev-Dev
Copy link
Collaborator

Irev-Dev commented Aug 2, 2023

They probably need to be broken now, here's an exerpt from models.ts

xport type ModelingCmd_type =
  | 'StartPath'
  | {
      MovePathPen: {
        path: ModelingCmdId_type /* The ID of the command which created the path. */;
        to: Point3d_type /* Where the path's pen should be. */;
      };
    }
    // ...

the union of a string and an object means that user's can't be more specific like

type MoreSpecificType = ModelingCmd_type['MovePathPen'] // not possible

Here are some hacks we're already using in the app to get around this

type SketchModeCmd = Extract<
EngineCommand['cmd'],
{ DefaultCameraEnableSketchMode: any }
>['DefaultCameraEnableSketchMode'];

and

    const command: Models['ModelingCmdReq_type'] = {/*...*/}
    const cmd:  = command.cmd
    if (typeof cmd !== 'string' && "CameraDragMove" in cmd && this.lossyDataChannel) {
       // do stuff with CameraDragMove cmd
    }

These are good work around but wouldn't want other users of this lib to have to do trick typescript stuff like this.

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

1 participant