-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
pipe
loses generics (2)
#35167
Comments
The missing signature: declare function isString(candidate: any): candidate is string; |
Thanks @karol-majewski, updated my description. |
This is not really related to const a: (x: "foo") => "foo" = filter(isString); // infers A as any
const b: (x: "foo") => "foo" = filter(v => isString(v)); // infers A as "foo" The problem is that in the first case there is not floating argument lacking a type annotation, so any type inference is done by directly unifying In the second case the TLDR: eta expansion of a function introduces "wiggle" room that lets contextual typing make inferences. Without the exapansion you're committing to inferences obtained from the declared type of This is similar to why in the following case: const a1 = isString;
const b1 = v => isString(v); The type of I guess the argument in the original example might be that when collecting inferences for |
@jack-williams Thanks for your explanation! Should we label this as a suggestion? |
Worth noting that a kinda gross workaround exists 👀 Edit: actually, the type parameter doesn’t even have to be used. (I was surprised that |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.6.3
Search Terms:
Code
Expected behavior:
Actual behavior:
Playground Link:
Related Issues:
#30727
The text was updated successfully, but these errors were encountered: