jsigbiz / spec

JavaScript signature notation
131 stars 6 forks source link

remove optional types #26

Closed Raynos closed 9 years ago

Raynos commented 9 years ago

An optional type can either have an optional label or be an optional type.

Let's compare

foo : (A, B?, C) => void

foo2 : (A, b?: B, C) => void

There is a difference between an optional type and an optional label.

An optional label means the argument is optional.

i.e. foo2(A, C) is valid.

An optional type means the type B is nullable

i.e. foo(A, null, C) is valid.

Most of the time when you think optional what you really mean is an optional argument.

It's recommended that if you truly want a nullable type you be more explicit about it. i.e.

foo3 : (A, B | null, C) => void

This PR removes optional types completely and tells you to use optional labels.

cc @jden @Matt-Esch

junosuarez commented 9 years ago

Ah, the old nullable issue. I was taking the B? nullable syntax from C#. You're quite right that it is confusing to use similar looking syntax for both optional labels and optional values. I'm happy to use type combinators to make it more explicitly nullable like you have here.