Skip to content

'this' not inferred for immediately invoked .bind()/.call()/.apply() #44224

@DexterHaxxor

Description

@DexterHaxxor

Bug Report

🔎 Search Terms

function type inferrence, function apply function, function call function

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about type inference

⏯ Playground Link

Playground link with relevant code

💻 Code

let f2 = function(this: number[]) {
    console.log(this)
}.bind([1, 2, 3]);
// ^^ works fine

let f1 = function() {
    console.log(this)
// ^^ 'this' implicitly has type 'any' because it does not have a type annotation.
}.bind([1, 2, 3]);

🙁 Actual behavior

Compiler shows an error: "'this' implicitly has type 'any' because it does not have a type annotation."

🙂 Expected behavior

The type of this to be correctly infered from the bind, call or apply call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions