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

union type not recognised when using inheritance/interface #28805

Closed
Burgov opened this issue Dec 2, 2018 · 2 comments
Closed

union type not recognised when using inheritance/interface #28805

Burgov opened this issue Dec 2, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@Burgov
Copy link

Burgov commented Dec 2, 2018

TypeScript Version: 3.2.0

Search Terms:
union, interface, extends

Code

interface i {
    getSomething(): 'a' | 'b';
}

class B implements i {
    getSomething() {
        return 'a';
    }
}

Expected behavior:
Compiles just fine

Actual behavior:
Gives error:

Property 'getSomething' in type 'B' is not assignable to the same property in base type 'i'.
  Type '() => string' is not assignable to type '() => "a" | "b"'.
    Type 'string' is not assignable to type '"a" | "b"'.

Playground Link:
https://www.typescriptlang.org/play/index.html#src=interface%20i%20%7B%0D%0A%20%20%20%20getSomething()%3A%20'a'%20%7C%20'b'%3B%0D%0A%7D%0D%0A%0D%0Aclass%20B%20implements%20i%20%7B%0D%0A%20%20%20%20getSomething()%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20'a'%3B%0D%0A%20%20%20%20%7D%0D%0A%7D

Related Issues:
No

@weswigham
Copy link
Member

See #23911 for discussion here. We'd like to change our behavior here, but we know it could be breaking.

@weswigham weswigham added the Duplicate An existing issue was already created label Dec 4, 2018
@typescript-bot
Copy link
Collaborator

This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed automatic house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants