sirisian / ecmascript-types

ECMAScript Optional Static Typing Proposal http://sirisian.github.io/ecmascript-types/
453 stars 4 forks source link

Handle ambiguous syntax with function types and union types. #82

Open sirisian opened 1 year ago

sirisian commented 1 year ago
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.