Skip to content

JS: Can't assign to superclass property #26284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ghost opened this issue Aug 7, 2018 · 1 comment
Open

JS: Can't assign to superclass property #26284

ghost opened this issue Aug 7, 2018 · 1 comment
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation
Milestone

Comments

@ghost
Copy link

ghost commented Aug 7, 2018

TypeScript Version: 3.1.0-dev.20180807

Code

a.js

class A {
    constructor() {
        this.initializer = 2;
    }
}

class B extends A {
    constructor() {
        super();
        this.initializer = this.initializer + 1;
    }
}

Expected behavior:

No error.

Actual behavior:

src/a.js:10:9 - error TS7022: 'initializer' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

10         this.initializer = this.initializer + 1;
@ghost ghost added Bug A bug in TypeScript Salsa Domain: JSDoc Relates to JSDoc parsing and type generation checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically labels Aug 7, 2018
@ghost ghost assigned sandersn Aug 7, 2018
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.1 milestone Aug 8, 2018
@sandersn
Copy link
Member

sandersn commented Aug 10, 2018

Ideally, I think the solution is to check this.initializer in B as if its initaliser were super.initalizer + 1, since that is the intent (and no matter what @RyanCavanaugh tells me, is 10 times saner than this.i = this.i + 1).

However, we're not well equipped to do this, I think. checkThisExpression would have to know to delegate to checkSuperExpression, and I think the check for that would be brittle.

@weswigham weswigham added Domain: JavaScript The issue relates to JavaScript specifically and removed Domain: JavaScript The issue relates to JavaScript specifically Salsa labels Nov 29, 2018
@sandersn sandersn modified the milestones: TypeScript 3.4.0, Backlog Mar 13, 2019
@sandersn sandersn removed their assignment Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation
Projects
None yet
Development

No branches or pull requests

4 participants