Skip to content

property access on unioned objects and string indices #17361

Closed
@KiaraGrouwstra

Description

@KiaraGrouwstra

Although not originally mentioned in the laws of union types (#805), I would generally expect a union of types undergoing a transformation to be equivalent to the result of its constituents undergoing the same transformation (distributive law?).

TypeScript Version: 2.5.0-dev.20170626, presumably any version from the introduction of union types

Code

type x = ({ a: 1 } | { a: 2 })['a'];
// 1 | 2
type y = { [k: string]: 3 }['a'];
// 3
type z = ({ a: 1 } | { a: 2 } | { [k: string]: 3 })['a'];
// ^ Property 'a' does not exist on type ...

Expected behavior:
z: 1 | 2 | 3

Actual behavior:
Property 'a' does not exist on type ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions