Skip to content

In JS, assignment to property of class has no contextual type #26748

Open
@ghost

Description

TypeScript Version: 3.1.0-dev.20180829

Code

class C {
    /**
     * @param {number} n
     * @return {number}
     */
    m = n => n * 2;
}

const c = new C();
c.m = n => n * 3;

Expected behavior:

No error.

Actual behavior:

src/a.js:10:7 - error TS7006: Parameter 'n' implicitly has an 'any' type.

There is no error for the equivalent TypeScript code (using m = (n: number): number => n * 2;).

Related Issues:

#25926

Activity

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

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationDomain: JavaScriptThe issue relates to JavaScript specificallycheckJsRelates to checking JavaScript using TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions