Conversation
javascript/sdk/src/index.ts
Outdated
| const { machine_name } = await fvm.createMachine() | ||
| const { instruction_seq } = await fvm.exec('print(123) or 567') | ||
| expect(instruction_seq).toBe(0) | ||
| const result = await fvm.execResult(machine_name, instruction_seq!!!) |
There was a problem hiding this comment.
The use of triple exclamation marks (!!!) is not valid TypeScript syntax. It should be a single exclamation mark for non-null assertion.
| const result = await fvm.execResult(machine_name, instruction_seq!!!) | |
| const result = await fvm.execResult(machine_name, instruction_seq!) |
There was a problem hiding this comment.
you can use as many exclamation marks as you want!!!!!!!!!!!
There was a problem hiding this comment.
true, I think ellipsis is wrong here. But could the intent of the code be made more legible using new Boolean(...)? As a reader I'm not sure how it's different than a single !.
There was a problem hiding this comment.
this is a non-null assertion — the type is number | undefined and i want it to be number. as number is probably harmless here, i just avoid that in general since you can accidentally cast the type incorrectly if you're not careful. !!! is just more greppable than ! — the likelihood of using it as a unary not is low because it's the same as a single ! (and even if you wanted to coerce to a boolean you'd only use two: !!)
wordier justification if you're interested: https://til.jakelazaroff.com/typescript/assert-that-a-variable-is-not-null-or-undefined/
the real question is, is this property truly optional? is there a case in which the response to exec doesn't include an instruction_seq?
There was a problem hiding this comment.
if the instruction failed to be submitted (because an existing one is running and it is not interruptable), it won't have an instruction_seq
9f63d71 to
1ff5f54
Compare
No description provided.