Skip to content

Literal type initialization with inheritance #10484

Closed
@jods4

Description

@jods4

TypeScript Version: nightly (2.1.0-dev.20160822)

Code

class A {
 protected x: "a" | "b";
}

class B extends A {
  protected x = "b";
}

Expected behavior: Should compile without error. Code seems intuitive to me.

Actual behavior: error TS2415: Class 'B' incorrectly extends base class. Type 'string' is not assignable to type '"a" | "b"'.

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