-
Notifications
You must be signed in to change notification settings - Fork 10
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
Merge to eliminate optionals #30
Comments
Hey, this would be a handy feature, but so far I haven't been able to get that working due to not being able to get the types merged in that way so that it can do it more intelligently, with the types of later properties overriding earlier ones (though that gets even more complicated if you've assigned a type to the object that's optional, especially if you explicitly provide a property as If you're working with declared types though, I'd recommend using Pull requests are welcomed though if you'd like to have an attempt at getting it working more like what you're expecting/what I've described 🙏🏻 |
To be perfectly honest, I also wouldn't know how to merge types like that. I'm pretty sure it's possible though, perhaps through Narrowing or a similar mechanism. |
Yeah it's quite a tricky one - especially to get the types to be more aware of all the logic that happens when merging in the runtime code, as well as the various options. This is why the types work as they do currently as a sort of "best guess", referencing all possible types from the merge. You can have a look at how the types work here for context. I'll leave this issue open for now in case anyone would like to open a PR to address it, so that there's this discoverable context around it. To work around it though in use cases where you're working with declared types and have the awareness of what it will actually output, I'd definitely recommend using the |
Actually, I've just added this context to the readme file and linked to this issue, so will close this issue for now, as I'm still not aware of a way for the type inferring to work as described here while still allowing an infinite number of args, as type narrowing is more for inferring the return type from the runtime logic, which isn't how |
Consider this snippet:
In this snippet, I would expect the values to get merged. They are. So far so good. But I would expect the same for the types. Merging a required and optional member of the same name, should result in that type becoming a required one. That is, among others, what I think merging types should be about.
It should be more than just simply "orring" them together.
The text was updated successfully, but these errors were encountered: