Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@akanshaa-18
Copy link

Filled the 'unknown' types with actual types.
Resolves: MWPW-175569

Copy link
Collaborator

@sharmrj sharmrj left a comment

Choose a reason for hiding this comment

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

I'd prefer if an Instruction encoded a single instruction.
Also we should use tagged unions.

type Instruction = InstructionType1 | InstructionType2 | ...;
type InstructionType1 = {
  type: "InstructionType1";
  selector: string;
  ...
}

// This way we can do the following in the future:

const handleInstruction = (instruction: Instruction): void => { // for example
  switch (instruction.type) {
   // ts error if the type is not in the tagged union
    case "InstructionType1": f();
      break;
    case "InstructionType2":  g();
      break;
    default: {
      // we get a type error if we aren't handling every case
      const exhaustivenessCheck: never = ""
    }
  }
};

Comment on lines +4 to +9
requestId: string;
handle: Array<{
payload: any[];
type: string;
[key: string]: any;
}>;
Copy link
Collaborator

@sharmrj sharmrj Jun 26, 2025

Choose a reason for hiding this comment

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

Avoid using any. We want to explicitly write out the type of handle because if we don't have something, or have something extra, we get a typeerror at compile time. Using any defeats the purpose of using typescript.

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