Skip to content

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

Closed
@bpasero

Description

@bpasero

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptVS Code PriorityCritical issues that VS Code needs fixed in the current TypeScript milestone

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions