Skip to content

Wrong type when function signature changes #55720

Closed as not planned
Closed as not planned
@NilsIrl

Description

@NilsIrl

🔎 Search Terms

  • function signature
  • wrong type
  • changed
  • re-assigned
  • re-declared
  • type inference

🕗 Version & Regression Information

  • This is the behavior in every version (3.3.3333 and 5.2.2) I tried, and I reviewed the FAQ for entries about bugs that aren't bugs.

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.2#code/DYUwLgBAzg9gtiAYgVwHYGMIF4IAoCGAXBAPIBGAViOmAJTYB8E+A3AFDoypST7bTwkadLgDeAX1rtYCFBn656WJgFZ2nbpDL8ZQjIpZA

💻 Code

let someFunc = (a: Object) => a;
const a = someFunc({});
someFunc = () => 5;
const b = someFunc();

🙁 Actual behavior

It doesn't compile and there is an error on the second call to someFunc saying that an argument is not supplied.

🙂 Expected behavior

Because someFunc was redefined it doesn't actually expect an argument and the code is correct.

Additional information about the issue

When using the function keyword, the inferred type is correct (although it doesn't compile either but this time because there is a duplicate function implementation):

https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAZzgWwKYDFwQBQCGAXIgPIBGAVhtAJSIDeiAThlCM0gQNyIC+AKAgJkURAUQBeFOmy48DPrW4DQkWAhmYckPPSat2nRn16DhYUYnJStc3cqA

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions