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

TypeScript does not recognize getters with union types #5776

Closed
wesleycho opened this issue Nov 24, 2015 · 2 comments
Closed

TypeScript does not recognize getters with union types #5776

wesleycho opened this issue Nov 24, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@wesleycho
Copy link

I have a particular setup

class Foo {
  get bar() {
    return 'foobar';
  }
}

class Bar {
  get foo() {
    return 'foobar';
  }
}

class Foobar {
  data: Foo | Bar;

  baz() {
    if (isFooInstance(this.data) {
      return this.data.bar;
    }
  }
}

TypeScript throws an error in this situation saying bar does not exist on Foo | Bar - this is incorrect behavior IMO, especially if I have already screened out what type it is via other mechanisms.

@RyanCavanaugh
Copy link
Member

Duplicate of #3812

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 24, 2015
@wesleycho
Copy link
Author

Ah sorry, couldn't find anything mentioning union types in particular when searching for issues.

@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

2 participants