Adding types in Personalize.js and Parseinstructions.js#2
Open
akanshaa-18 wants to merge 1 commit intoadobecom:mainfrom
Open
Adding types in Personalize.js and Parseinstructions.js#2akanshaa-18 wants to merge 1 commit intoadobecom:mainfrom
akanshaa-18 wants to merge 1 commit intoadobecom:mainfrom
Conversation
sharmrj
requested changes
Jun 26, 2025
Collaborator
sharmrj
left a comment
There was a problem hiding this comment.
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 = ""
}
}
};
sharmrj
reviewed
Jun 26, 2025
Comment on lines
+4
to
+9
| requestId: string; | ||
| handle: Array<{ | ||
| payload: any[]; | ||
| type: string; | ||
| [key: string]: any; | ||
| }>; |
Collaborator
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Filled the 'unknown' types with actual types.
Resolves: MWPW-175569