Skip to content

Implicit Function Parameter Types won't Work in JavaScript #65086

Open

Description

🔎 Search Terms

implicit function lambda parameter types javascript checkjs ts-check

🕗 Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about implicit function parameter type detection

⏯ Playground Link

https://www.typescriptlang.org/play/?filetype=js#code/DYUwLgBMD20NYFcAOEC8EAUB6AVDiAAmAJ5IgQDeAdggLYBGIATgL4Q5YQCWAJgJRoAfBABEVAIa0QIgNwAoGPGRpMvAamEiAUtAAWVCABFo0mRCycA6tCZwAznIXgI9BHa5UQduwBloAcy4AYxUKOQgIiH9wAFFaJBhiEBBsPEISMkoaBmY2Dm5+SnDIkqZwBCYDMUlTYoiWOQbXd09vP0CggDposDiE6CTydAw1IVEdfSMTWXNOMqQbMDsIZiYbCABiAHYABh2ANkcMDHVhMJLmjy9fAODu2PjE5JURwo1xvQNjU1mIAHcbPZGnwTvI5EFgOJvBAAEJuK5tW4hc6RHp9J4pXD4IikcjUOiMVjsTijFElCJlMAVKoSKQiOoQBoNJyQejAFSeP6w+GtG4dUFyNn3XqPAbPYajd7aT5TH4WCDzRbLVbrbZ7Q5yY6nIoXYDC9FioaqN6aCZfaZmeUA2wOFggvjyIA

💻 Code

let lookup = (/** @type {number} */ id) => "name";
lookup = (id) => "John Doe"; // Works

let businessLogic = {
    getEmployee(/** @type {number} */ id) {
        return "name";
    }
}
businessLogic.getEmployee = (id) => "John Doe"; // reports error #7006

(() => {
    businessLogic.getEmployee = (id) => "John Doe"; // works
})();

class BusinessLogic {
    getEmployee(/** @type {number} */ id) {
        return "name"
    }
}

let bl = new BusinessLogic();
bl.getEmployee = (id) => "John Doe"; // reports error #7006

(() => {
    bl.getEmployee = (id) => "John Doe"; // works
})();

🙁 Actual behavior

The parameter type inference of functions don't work under very specific circumstances:

  • A function within an object-variable is being assigned
  • The function is being assigned in a JavaScript file with either checkJs enabled or // @ts-check
  • The function is being assigned outside of a function body

In these cases, the language server reports the error Parameter 'xxx' implicitly has an 'any' type. instead of detecting the type of the parameter from the type declarations.

🙂 Expected behavior

In the example code, the type of the id parameter should always be detected as number instead of reporting errors.

Additional information about the issue

No response

Activity

  1. neurolag commented on Nov 1, 2026

    @neurolag
    ContributorAuthor

    Perhaps, this is related to #44640

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions