paldepind / union-type

A small JavaScript library for defining and using union types.
MIT License
478 stars 28 forks source link

Remove requirement of nesting perhaps? #9

Closed timoxley closed 9 years ago

timoxley commented 9 years ago

Would be good if one could define types without requiring nesting inside an object:


// e.g. pass array without nesty object
const Point = Type([isNumber, isNumber])

var p = Point('bad', 4) // no Point.Point :)

// or pass a function directly
const SomeNumber = Type(isNumber)
const AlternativePoint = Type([SomeNumber, SomeNumber])
var p = AlternativePoint('bad', 4) // still no nesting
paldepind commented 9 years ago

I think you're confusing types with values. If you where to define the boolean type with union-type it would look like this:

var Boolean = Type({True: [], False: []});

Here Boolean is the type and True and False are values. So what you're asking is really to define a value without it belonging to a type.

What benefits do you think this would offer? Maybe a shortcut for defining a type with only a single possible value would be better?

timoxley commented 9 years ago

hm, I don't know what I'm asking anymore, nvm. :+1:

paldepind commented 9 years ago

No problem!