-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Inferred implicit any from constructor call #10978
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
The thought process in the code basically runs like this:
The issue here is that we can't actually know that it's correct to apply the contextual |
Thanks for explaining @RyanCavanaugh. For anyone encountering this, a workaround is to explicitly annotate const a: M = new M(() => a); In terms of impact, it's more problematic when you are not using |
Followup question -> when the compiler 'bails out' because it detects an infinite type-checking loop, is If the compiler bailed out with |
Consider this unannotated code function fac(n) {
return n === 1 ? 1 : fac(n - 1) * n;
} We infer the return type of function fac(n): { } {
return n === 1 ? 1 : fac(n - 1) * n;
} Now you get an error that you can't use the |
Thanks @RyanCavanaugh, makes sense. There may be some cleverer way of analysing recursive types, but that would presumably involve substantial changes to the compiler. That can be for another issue. |
TypeScript Version: nightly
2.1.0-dev.20160918
Code
Expected behavior:
No errors. Inferred type of
a
isM
.The expression
new M(...)
always has typeM
, it does not depend on the argument used inM
's constructor.Actual behavior:
Compiler error as shown in code comment.
The text was updated successfully, but these errors were encountered: