-
Notifications
You must be signed in to change notification settings - Fork 757
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
Replace Object.assign calls and fix type errors #529
Conversation
Does the spread operator help the compiler detect errors compared to Re 1.: Here are where those values are consumed: So the Re 2.: |
I think so. interface A {
n: number
s:string
}
const a: A = Object.assign({n:123}, {s:"a"}, {s: 123})
// a.s === 213 The literal with spread operators keeps the last type for each field. This is how it behaves at runtime too, so it makes more sense and helps catch errors. This version const a: A = {
...{n:123},
...{s:"a"},
...{s: 123}
} results in this type error:
I tried adding
That return value is probably the most complex part of this codebase. It's pretty scary. I'm in favor of simplifying it, but I have no idea what that implies. |
That's a very good point, thanks for the explanation. I'll try to use the spread operator from now on.
Let's do the simplification in a future PR. For now can you please make |
1cd00c7
to
13fda7d
Compare
I did that and got a type error again. I think I was confused about it, and that now I fixed it correctly. Please take a look at the last commit. |
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 for the fix, looks good to me. We should really simplify the return values though :)
Everyone is getting so creative on improvements 😄, I think we really should give it yet another 1-2 weeks until the |
While reviewing the codebase some calls to
Object.assign
caught my attention, as I suspected that they may be hiding some type errors.I replaced them with object literals using the spread operator (i.e.
{ ...obj }
) and normal field assignments to check if that was the case.My suspicion turned out to be right, and I found two type errors in
Interpreter#runLoop
:Loop#run
returned an exception,null
was set as the result'sgasRefund
andselfdestruct
fields.runState
didn't type.I tried to fix them, but I'm not familiar enough with the codebase as to be sure that my changes are correct.
For 1, I replaced the
null
s with the default values used to initialize those fields.For 2, I made
LoopResult#runState
non-optional, as I didn't find any instance of it beingundefined
.