-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
noImplicitAny incorrectly permits 'any' when returned via arrow function #7220
Comments
@mhegazy - I see you've added the 'Community' milestone.
How are issues tagged with a milestone of 'Community' prioritised within the TypeScript core team? Or does the 'Community' milestone mean that this issue is essentially waiting for a contribution from non-core members? Thanks |
|
The problem is not
function f(): any {}
let x = f(); // ok, any
let x = mine<any>(() => undefined); // ok, any On the other hand the lambda let f = () => undefined;
// error: Function expression, which lacks return-type annotation, implicitly has 'any' return type. But the lambda can't be immediately rejected, because its return type might be dictated by context. In fact the following is ok: // ok because of explicit type parameter dictating the return type
let x = mine<any>(() => undefined); My guess is that the compiler is going full circle with the generic parameter.
That might be tricky to sort out... |
When should the error be reported? The lambda is inferentially typed by Here's another thought. If the return expression were not widened, the error would still be missing because we do not report noImplicitAny errors resulting from widening after type argument inference. So while I agree that #241 should be fixed, I'm not sure that would cause the error be reported in this case. |
Is this another instance of the same problem? interface Class<T> {
new (...args: Array<any>): T;
}
class A<T> {
private t: Class<T>;
constructor(t: Class<T>) {
this.t = t;
}
}
class B<T> {
private f: T;
}
function Example<T>(a: Class<T>): B<T> {
return new B<T>();
}
let x = Example(A); // type is B<A<any>> |
@myitcv I don't think that has to do with widening. I think the problem there is that in the process of inferring T for the example call, you end up having to match |
Thanks @JsonFreeman - does this warrant another issue tracking the 'problem' here? |
Yes, I think that should be a new issue. |
To clarify, I think we can use this issue to track that since a fix would potentially need to solve both. If it's doesn't, we can open a new one. Maybe @JsonFreeman meant something else. |
Sorry, didn't mean to manage the issue tracking. I just meant that I think the problems have two different (and independent) causes, so I imagine they'd need two different fixes. But that is a hunch. |
Thanks for clarifying @DanielRosenwasser |
This seems to have been fixed, |
It's an unreported |
Apologies for the vague title, I can't quite pin down the cause of this, hence the poor wording
The problem is best described using the following example:
The text was updated successfully, but these errors were encountered: