-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix undefined steps for partial workflow #5
Conversation
The latest Buf updates on your PR.
|
src/main.ts
Outdated
@@ -55,8 +54,8 @@ async function main() { | |||
// NB: Write empties the buffer must be after the comment. | |||
await summary.write(); | |||
// Finally, set the status of the action. | |||
for (const key of Object.keys(steps)) { | |||
if (steps[key].status == Status.Failed) { | |||
for (const [key, value] of Object.entries(steps)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Object.entries
looses the type and goes to string, any
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, unfortunately typescript is representing javascript correctly here. Steps could contain other things. You could help it be explicit with something like:
for (const [key, value] of Object.entries(steps) as [
keyof Steps,
Result | undefined
][]) {
Will suffice to make TS happy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Added the type sig, but still don't get an error on value.status
vs value?.status
. Seems like the value doesn't respect the undefined or it makes no diff to the type check here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that is weird, haven't seen it such that it coerced. Might be a TS option that I'm missing somewhere.
Have an error report of:
Error: Cannot read properties of undefined (reading 'status')
. I believe it's from thesteps[key].status == Status.Failed
if the value is in the object but undefined. Removed the class for an object that is allowed to be partial and added more?.
guards for field access.