Skip to content

CallableFunction inference does not match runtime behavior #30294

Closed
@karol-majewski

Description

@karol-majewski

TypeScript Version: 3.4.0-dev.20190309

Search Terms: CallableFunction, call, bind, inference

Code

Promise.resolve.call(1)           // Compiles without error, throws in runtime
Promise.resolve.call(Promise, 1); // Compile-time error, works fine in runtime

Expected behavior:

  • Promise.resolve.call(1) should trigger a compile-time error
  • Promise.resolve.call(Promise, 1) should compile

Actual 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, throws Uncaught TypeError: PromiseResolve called on non-object in runtime
  • Promise.resolve.call(Promise, 1) gives a compile-time error (Expected 1 arguments, but got 2.), works fine in runtime (returns a Promise<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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions