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

Readonly vs. litteral type breaking change? #12148

Closed
stephanedr opened this issue Nov 10, 2016 · 3 comments
Closed

Readonly vs. litteral type breaking change? #12148

stephanedr opened this issue Nov 10, 2016 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@stephanedr
Copy link

TypeScript Version: 2.1.1

Code

class A {
    readonly n = 0;
    constructor() {
        this.n = 1;  // Type '1' is not assignable to type '0'
    }
}

class B {
    constructor(readonly n = 0) {}
}

class C extends B {
    constructor() {
        super(1);  // Argument of type '1' is not assignable to parameter of type '0 | undefined'.
    }
}

Expected behavior:
Is this behavior expected (breaking change vs 2.0.8)?
To me this should be valid, particularly the 2nd case.

Actual behavior:
Errors displayed in comments.

@mhegazy mhegazy added the In Discussion Not yet reached consensus label Nov 10, 2016
@mhegazy mhegazy added this to the TypeScript 2.1.3 milestone Nov 10, 2016
@falsandtru
Copy link
Contributor

#11409

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript and removed In Discussion Not yet reached consensus labels Nov 11, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Nov 14, 2016

All parameter initializes should be widened to their base (e.g. class B), property initializes (e.g. class A) are intentional breaking change.

@sandersn
Copy link
Member

Fix is up at #12312

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Nov 16, 2016
@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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants