Skip to content

Implementing only a Setter is enough to implement an Interface #33621

@willemneal

Description

@willemneal

TypeScript Version: 3.6.3

Search Terms: only setter in class implements interfaces. Interface property bugs.

Code

interface Properties {
  val: number;
}

class BadProps implements Properties {
  private _val: number = 42;
  set val(newVal: number) {
    this._val = newVal;
  }
}

Expected behavior:
A type error that the implementing class is missing the getter.

Actual behavior:
Just runtime error of undefined.

Playground Link:
Above example

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions