Skip to content

Improve union types of the modelling comands #142

@Irev-Dev

Description

@Irev-Dev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions