-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
[experiment] Improve Effects assignability after adding Symbol.iterator
by replacing void
s with unknown
#2636
base: main
Are you sure you want to change the base?
Conversation
…cing `void`s with `unknown`
|
Nice! |
This is part of a larger discussion about using "void" instead of "unknown" when we don't care about the value of an effect, in theory it would make sense |
Thanks for taking the time to look at this :) Replacing |
What kind of semantics you'd lose? I find declare const test: string | void | undefined;
if (test === undefined) {
test; // void | undefined
} else {
test; // string
} |
Mainly you lose some meaning / intent. This function returns nothing (void) vs this function could return anything but we don't care what (unknown). |
Void doesn't mean that this function returns nothing, it means that we don't care about the return |
Yeah, so in that sense usually either This is perfectly valid: const test: () => void = () => 42; |
But in terms of familiarity for the majority of developers, most of them know that const myFn = () => {
// No explicit return
} Will infer a return type of |
yes it will infer void, but you can also type void and return, the meaning really is "whatever" and given it is sometimes treated as undefined it creates potential issues |
This is not for merging, I just put it together since I was curious if I could make it work this way. This work was started based on the initial commit from #2602
It doesn't (yet?) allow you to remove the adapter thing from this branch but perhaps this is just missing some minor thing. I'm not sure if there were any extra changes done by @tim-smart to allow that. This PR focuses solely on making this to typecheck with the added
Symbol.iterator
method.There are a few minor TODO comments here but all of them (but one!) are really about the same thing - adding
Symbol.iterator
properly to your error classes.