Syntax for union types

liorean liorean at gmail.com
Fri Oct 26 17:22:01 PDT 2007


On 27/10/2007, James Clark <jjc at jclark.com> wrote:
> (int, string) doesn't seem to me to be a syntax that the average JS
> programmer will guess means union. I would have thought a better choice
> would be (int | string) (especially given that regexps use |) or a keyword.

Honestly, there's very little in the type system that I think will
come entirely natural for ES3 users. Annoted object types look like
object initialisers with name-value pairs, annoted array types look
like array initialisers, the constructor syntax looks entirely weird,
parametric types don't look like anything else in the language etc.
And other parts too - destructuring assignment, array comprehensions
etc, all look slightly foreign.

I really don't think this syntax is that very foreign (it's a quite
natural way to list different types something can be after all), and
with all the new syntax related to typing, as well as other syntax
additions, it's going to be one tiny part of an entire new domain to
learn.
-- 
David "liorean" Andersson



More information about the Es4-discuss mailing list