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

A readonly interface property can be implmented as writeonly class property? #39871

Closed
jamesfancy opened this issue Aug 3, 2020 · 3 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@jamesfancy
Copy link

TypeScript Version: 4.0.0-Beta

Search Terms:

  • getter setter
  • writeonly property
  • readonly property

Code

interface ITest {
    readonly name: string;
}

class Test implements ITest {
    #_name: string = "";
    set name(value: string) { this.#_name = value; }
}

const test = new Test();
test.name = "James";

const it = test;
console.log(it.name);

Expected behavior:

TSC can report a error since Test does not implment get name accessor.

ITest declare name property is readonly, that means name is readable. But name property of Test is not readable. It's against the interface.

Actual behavior:

No Error.

Playground Link: Provided

Related Issues:

maybe related to #12, but they are different.

@yw662
Copy link

yw662 commented Aug 20, 2020

#21759 might be another way to think of this

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 20, 2020
@RyanCavanaugh
Copy link
Member

TS doesn't have a notion of a "writeonly" property (see prior comment) so a property is always assumed to have a read side.

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants