union type syntax

# Peter Hall (18 years ago)

Now that union type uses "|" instead of "," for the delimiter, could the parentheses be made optional? It seems like parentheses are used elsewhere only for grouping and function calls/definitions.

UnionType ::=  Type ( "|" UnionType )?

which should be easily distinguishable from a bitwise OR expression.

Peter

# Lars Hansen (18 years ago)

The parens are required. Long discussion here: bugs.ecmascript.org/ticket/308

# Waldemar Horwat (18 years ago)

There is no solid technical reason for requiring parentheses here. They're here because of people's preferences. I don't find them particularly useful here.

Waldemar
# Peter Hall (18 years ago)

When programmers see a type union expression for the first time, and are going to intuitively understand "|" to be an operator, which has a new meaning when applied to types. Programmers routinely use parens around complex expressions that involve multiple operators, for readability and to ensure they didn't make a mistake around operator precedence. But parens are never required in those places, and it would add an odd asymmetry to the language to require them here.

I vote they are dropped unless there is a compelling technical reason, related to machine parsing.

Peter