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

Implements readonly property should be readonly #11578

Closed
dungdm93 opened this issue Oct 13, 2016 · 5 comments
Closed

Implements readonly property should be readonly #11578

dungdm93 opened this issue Oct 13, 2016 · 5 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@dungdm93
Copy link

dungdm93 commented Oct 13, 2016

TypeScript Version: 2.0.3

Code

interface I {
    readonly name: string;
}

class C implements I {
    public name: string;
}

let c: C = new C();
c.name= "I going to change it";

Expected behavior:
Compilation error. C.name should be declared as readonly.

Actual behavior:
Compilation success. No errors/warnings

@aluanhaddad
Copy link
Contributor

The class correctly implements the interface. I know this is a duplicate but I can't seem to find the corresponding issue.

Regardless, readable & writable is assignable to readable.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 14, 2016

thanks @aluanhaddad

@mhegazy mhegazy closed this as completed Oct 14, 2016
@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Oct 14, 2016
@yortus
Copy link
Contributor

yortus commented Oct 14, 2016

TypeScript is allowing assignment both ways - shouldn't there be a compile error in the following? (There might be an issue open for that but I couldn't find one).

interface I {
    readonly name: string;
}

interface C {
    name: string;
}

let i: I;
let c: C;

i = c; // OK, readable & writable is assignable to readable
c = i; // OK but why? readable shouldn't be assignable to readable & writable

@mhegazy
Copy link
Contributor

mhegazy commented Oct 14, 2016

@yortus I believe #11481 covers this request.

@yortus
Copy link
Contributor

yortus commented Oct 14, 2016

Yes that's it exactly, thanks @mhegazy

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants