Skip to content

readonly modifier is ignored in unions #9108

Closed

Description

interface X {
    readonly value: 'x';
}
interface Y {
    value: 'y';
}
type Z = X | Y;
var z: Z = <Z>{ value: 'y' };
z.value = 'x'; // expected an error saying that value: 'x' is readonly and cannot be set, actual OK

UPDATE:

even this example doesn't work (with both possible options being readonly)

interface X {
    readonly value: 'x';
}
interface Y {
    readonly value: 'y';
}
type Z = X | Y;
var z: Z = <Z>{ value: 'y' };
z.value = 'x'; // expected an error saying that value: 'x' is readonly and cannot be set, actual OK

Activity

  1. sandersn commented on Jun 14, 2016

    @sandersn
    Member

    #9167 fixes this for unions and intersections.

  2. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions