Adding types in Personalize.js and Parseinstructions.js - #2
Conversation
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 = ""
}
}
};| requestId: string; | ||
| handle: Array<{ | ||
| payload: any[]; | ||
| type: string; | ||
| [key: string]: any; | ||
| }>; |
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.
|
No activity in 7 days. Will be labeled No activity in 14 days, labeled No activity in 21 days, labeled No activity in 28 days. Would normally close now, but auto-close is disabled this run. Add Rundeck job Git Stale PR Check (git-stale-pr-bot), execution 2739336, project global, run by casalino |
Filled the 'unknown' types with actual types.
Resolves: MWPW-175569