Skip to content

Intersection type operator doesn't discriminate Union Types #13203

Closed
@nahuel

Description

@nahuel
type A = {tag: 'a', a: 1} | {tag: 'b', b: 1}
type B = A & {tag: 'b'}

declare var b : B
let z = b.b    // Error: Property 'b' does not exist on type 'B'

Expected behavior: b (type B) only possible value for tag property is 'b', so it must be discriminated to {tag : 'b' , 'b' : 1} without needing to enclose it in a if(b.tag == 'b') type guard
Actual behavior: b (type B) is not discriminated, needs type guards just like plain A
TypeScript Version: 2.0.6

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