Skip to content
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

TS should show an error when defining only a getter in subclass but assigning in super class #36346

Closed
bpasero opened this issue Jan 22, 2020 · 1 comment
Labels
Bug A bug in TypeScript VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone
Milestone

Comments

@bpasero
Copy link
Member

bpasero commented Jan 22, 2020

TypeScript Version: 3.7.2

Code

class Foo {
    constructor(protected readonly something: string) {

    }
}

class Bar extends Foo {
    constructor() {
        super("something");
    }

    get something(): string {
        return "other";
    }
}

new Bar();

Expected behavior:
I would like to see a compile error.

Actual behavior:
There is no compile error. But the code will run with this error:

VM27:4 Uncaught TypeError: Cannot set property something of #<Bar> which has only a getter
    at new Foo (eval at <anonymous> (main-3.js:1239), <anonymous>:4:24)
    at new Bar (eval at <anonymous> (main-3.js:1239), <anonymous>:9:9)
    at eval (eval at <anonymous> (main-3.js:1239), <anonymous>:15:1)
    at main-3.js:1239

Playground Link: <!-- A link to a TypeScript Playground "Share" link which demonstrates this behavior Playground Link

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 27, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 27, 2020
@mjbvz mjbvz added the VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone label Aug 12, 2020
@RyanCavanaugh
Copy link
Member

This has been fixed in 4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone
Projects
None yet
Development

No branches or pull requests

3 participants