-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Assigning to field with a union type across functions #18
Comments
Currently not public, will be by the summer hopefully when I have more time.
Yes this is an interesting issue that is really important for type safety. Under the type rules (which follow TypeScript), it is valid to pass Haven't tested but it all the data should be present as Ezno does track mutation effects. I think it would throw a property does not exist on the |
Interestingly this is solved in Flow because they do not accept passing a general type to a union type. I don't like this behaviour and diverges from TS. So effects are the way to go here |
This sort of works. Given const x = { a: 2 }
function updateA(obj: { a: string | number }) {
obj.a = "hi"
}
updateA(x)
const y: number = x.a It errors with Need to test with arrays and currently doesn't respect if |
I think this is now solved with and Might come back to make more user friendly and double check all the edge cases are identified at some point, but for now it is at least identified 🎉 |
Where I can try Ezno? Please add some online sandbox where I can try Ezne online
Here is interesting example that makes you think about whole soundness of type checking
Does Ezno handle error in this example? (TypeScript doesn't). Here we have a runtime error because caller sets "obj.field = null" but callee does not expect this value. I think typecheker needs to calculate diff between passed type and type declared in parameter signature and make sure nothing from this diff set of values does not assign to parameter in the body of function in order to prevent runtime error. What do you think?
The text was updated successfully, but these errors were encountered: