Skip to content

Using "implements" causes an issue with string literal types. "extends" does not. #10071

Closed
@dsifford

Description

@dsifford

TypeScript Version: nightly (2.0.0-dev.201xxxxx)

Relevant StackOverflow discussion

Playground

Kudos to @nitzantomer for looking into this

Code

// This is defined in a d.ts file. 
class Test {
    someObj: {
        someString: 'this'|'that'|'the other'
    };
}

// This is me actually using the class.
class Test2 implements Test {
    someObj = {
        someString: 'this'
    }
}

Expected behavior:
No error thrown. Using literal 'this' as the value for someObj.someString correctly implements class.

Actual behavior:
Error thrown.

Class 'Test2' incorrectly implements interface 'Test'.
  Types of property 'someObj' are incompatible.
    Type '{ someString: string; }' is not assignable to type '{ someString: "this" | "that" | "the other"; }'.
      Types of property 'someString' are incompatible.
        Type 'string' is not assignable to type '"this" | "that" | "the other"'.
          Type 'string' is not assignable to type '"the other"'.

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