-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Inserting intersections with 'Function' while narrowing breaks code #26970
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
Comments
Mmmm kinda? Previously we only selected applicable union members, while now we also narrow the not-immediately-applicable ones like we do in the non-union case. In the case of primitives and literals, they evaporate into |
What does not immediately applicable mean? Why does this case work? function foo(x: { blah: number } | (() => string)) {
if (typeof x === "function") {
x()
}
} |
|
So it's probably worth mentioning that |
This caught me off guard today, after upgrading to typescript 3.1. I think it's not uncommon to have a parameter which is either a value or a function returning it - in our company we use it often for helper functions in tests. From a logical point of view it's strange that I can't call something I've just checked to be a function, especially since as @DanielRosenwasser showed it still works in some cases. So for me it's definitely a bug and not just something that requires a better error message. |
Just looking at old issues; the original repro here was fixed by #29265. Are there more cases to consider? |
@ahejlsberg and I ran into something like this in the RWC. This currently repros on the nightlies.
Expected: No error
Actual:
Potentially related to #25243.
The text was updated successfully, but these errors were encountered: