-
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
CallableFunction inference does not match runtime behavior #30294
Comments
@rbuckton bug or no? |
@RyanCavanaugh: This is likely due to overload resolution related to declare class C {
static x(y: number): number;
static x(): number;
}
C.x.call(C, 1); // error, but should be ok
C.x.call(C); // ok
C.x.call(1); // ok (not an error because the `this` type of `x` is not constrained) |
Note that if you switch the order of the overloads, you get the exact opposite results ( |
@RyanCavanaugh: Not a bug per se, as we have documented this is the expected behavior, however it does result in a poor user experience. |
TypeScript Version: 3.4.0-dev.20190309
Search Terms: CallableFunction, call, bind, inference
Code
Expected behavior:
Promise.resolve.call(1)
should trigger a compile-time errorPromise.resolve.call(Promise, 1)
should compileActual behavior:
The situation is reversed. The one that works in runtime does not compile. The one that does compile throws a runtime error.
Promise.resolve.call(1)
compiles without error, throwsUncaught TypeError: PromiseResolve called on non-object
in runtimePromise.resolve.call(Promise, 1)
gives a compile-time error (Expected 1 arguments, but got 2.
), works fine in runtime (returns aPromise<number>
)I'm using
"lib": ["dom", "esnext"], "target: "es2015"
. Tested on Chrome 72.0.3626.121, V8 7.2.502.28.Playground Link: The compile-time error is not there, but the runtime exception can be observed
The text was updated successfully, but these errors were encountered: