-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Failure to infer parameter type #25444
Comments
What is happening here is to infere the type of You can explicitly specify the type argument to the call: foo<{ bar(x: number): void }>({
f(p) { },
bar(x) { },
}); |
@mhegazy can you look at my revised example? What surprises me is that not even this works: const foo = <F extends (x: any) => any>(f: F, x: F extends (x: infer A) => any ? A : never) => f(x);
foo(
(x: (n: number) => void) => x(42),
n => console.log(n)
); Here the type of |
Conditional types do not contribute to inferences. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
I'd like to petition to get this reopened. It would vastly simplify the typing of a major library (Material UI) if we could get TypeScript to infer a reasonable least upper bound instead of |
TypeScript Version: 3.0.0-dev.20180704
Search Terms: parameter inference
For context, I'm trying to provide accurate typings for a JS library (Material UI). What follows is an extreme simplification of the problem, dealing with functions rather than components:
Code
Expected behavior:
Should infer the type of the
n
parameter of the second argument asnumber
.Actual behavior:
Infers
n: any
, which rightly fails whennoImplicitAny
is enabled. However the compiler clearly knows what the type of then
parameter should be... if it's annotated incorrectly, e.g.then we get an error saying
Playground Link
The text was updated successfully, but these errors were encountered: