Skip to content

Why is the & operator called an intersection? #420

@popham

Description

@popham

I had to check out the tests to figure out what the intersection operator does. My intuition says that an intersection of two types should yield a type that is of equal or greater strength than both operands. The & operator smells more like a sum to me. I guess it doesn't matter, but a {x:number}&{y:number} example in the docs would have saved me some aggravation.

It's probably too late, but I would expect an intersection operator to provide (string | number) \cap (string | SomeClass) = string and {x: number | string, y: string} \cap {x: string, y: number} = {x: string}. I could use this intersection operator as a workaround (type Null = ?string \cap ?number), but it could be useless in practice. I mention the alternative in case it justifies deprecating the & symbol in favor of a + symbol. Then an intersection (\cap or something else) could take the & symbol someday.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions