Skip to content

Fix all for add missing member quick fix does not work classes with similar property names #25297

@mhegazy

Description

@mhegazy

TypeScript Version: 3.0.0-dev.201xxxxx

Search Terms:

Code

class C {
    method() { 
        this.a = 0;
    }
}


class D {
    method() {
        this.a = 0;
    } 
}   

Expected behavior:

class C {
    a: number;
    method() { 
        this.a = 0;
    }
}


class D {
    a: number;
    method() {
        this.a = 0;
    } 
}   

Actual behavior:

class C {
    a: number;
    method() { 
        this.a = 0;
    }
}


class D {
    method() {
        this.a = 0;
    } 
}   

Playground Link:

Related Issues:

Discovered in https://github.com/Microsoft/TypeScript/pull/25182/files#r198680755

Caused by the use of the property name as a key for seen dictionary in the fixall code path.

One interesting problem here is the handling of inherited properties. we probably want to skip declaring a property in a derived class, first for brevity, and second to avoid conflicting type declarations when possible. if so, then the key will need to be a bit more involved than just a string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Quick FixesEditor-provided fixes, often called code actions.FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions