-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Case that infering type for parameters works for 3.3.0 but error in 3.4.0 #30840
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
Simpler repro // @noImplicitAny
// Error
const k1: any = (m = 3) => m;
// No error
const k2 = (m = 3) => m; |
@ahejlsberg Andrew and I were discussing this on teams and I disagree with part of the logic in #28816 (comment)
I don't see why this desirable at all. Unless there are call/construct signatures on the contextual type, this can only create new implicit |
Yes, after I upgraded the typescript package to |
@RyanCavanaugh Regarding this example: const k1: any = (m = 3) => m; // m: implicit any
const k2 = (m = 3) => m; // m: number I would absolutely argue that it is correct for the inferred type of Now, I think where this argument changes is when the contextual type is a generic type with a constraint. Just because the constraint says |
Possibly related to this, after upgrading from 3.3.1 to 3.4.5, I'm also getting implicit any errors for default parameters in a very specific case (see Case 3): declare function memoize<F extends Function>(func: F): F;
// Case 1: No error
function add(x: number, y = 0): number {
return x + y;
}
const memoizedAdd = memoize(add);
// Case 2: No error
const add2 = (x: number, y = 0): number => x + y;
const memoizedAdd2 = memoize(add2);
// Case 3: Error - Parameter 'y' implicitly has an 'any' type
const memoizedAdd3 = memoize((x: number, y = 0): number => x + y); Passing an arrow function expression directly to If this is unrelated to the original issue, I'd be happy to move this to a separate one. |
@bdpartridge That's exactly the issue I allude to here in my comment:
That's what we need to fix. |
@ahejlsberg That makes sense. Thanks for explaining. |
here's another surprising case:
|
@bdpartridge @christopherthielen The issues you point out above are now fixed in #36476. |
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
3.4.0 regression
parameter type infer
Code
The related tsconfig.json
Expected behavior:
No error. It's worth noting that it works in 3.3.4.
Actual behavior:
With the
tsc
command line, it outputs the following errors:Playground Link:
Related Issues:
The code works in 3.3.4 with no errors, but after upgrading to 3.4.0, the tsc complains that the parameter has 'any' type when the LHS
fn
is of any type. If I replacefn: any =
withfn =
, it works for 3.4.0.The text was updated successfully, but these errors were encountered: