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

Type comparison incorrect with inherited string literals #13985

Closed
davewasmer opened this issue Feb 9, 2017 · 1 comment
Closed

Type comparison incorrect with inherited string literals #13985

davewasmer opened this issue Feb 9, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@davewasmer
Copy link

TypeScript Version: 2.2.0

Code

class Foo {
    bar: "boop";
}
class Buzz extends Foo {
    bar = 'boop'
}

Playground Link

Expected behavior:

Compiles without error.

Actual behavior:

Class 'Buzz' incorrectly extends base class 'Foo'.
  Types of property 'bar' are incompatible.
    Type 'string' is not assignable to type '"boop"'.

Apologies if I'm missing something obvious, this is by design, or there are existing issues for this. I searched and didn't find anything like it.

@ahejlsberg
Copy link
Member

See #6118. Ideally we'd have the declaration of bar in Buzz somehow contextually typed by the declaration of bar in Foo, but it turns out not to be an easy change.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 10, 2017
@mhegazy mhegazy closed this as completed Apr 21, 2017
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants