Skip to content

Can't access potential member on union type #18750

Closed
@testerez

Description

@testerez

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

Code

interface Foo {
  foo: string;
}

interface Bar {
  bar: string;
}

function test(item: Foo | Bar) {
  console.log(item.foo || item.bar)
}

Expected behavior:
This pattern is very common in javascript, that would be great to make it valid in typescript.

Actual behavior:

Property 'foo' does not exist on type 'Foo | Bar'.
  Property 'foo' does not exist on type 'Bar'.
Property 'bar' does not exist on type 'Foo | Bar'.
  Property 'bar' does not exist on type 'Foo'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions