ecmascript-types icon indicating copy to clipboard operation
ecmascript-types copied to clipboard

Handle ambiguous syntax with function types and union types.

Open sirisian opened this issue 2 years ago • 0 comments

const a:(b):c|d;

Is d part of the return union type or is it (b):c or d. In this case it can be rewritten as: const a:d|(b):c; to remove the ambiguity, but the order of types shouldn't matter in a union.

Keep in mind the return type can also be a function.

const a:(b):c|(e):f|g;

(b):c|(e):f or g
(b):c or (e):f or g

Ideally one would define a type separately as this is complex to read, but when prototyping it might be useful to be able to type a one-liner type. These function or something else might be rare. Except for null which might be common.

sirisian avatar Dec 18 '22 04:12 sirisian