jsigbiz / spec

JavaScript signature notation
131 stars 6 forks source link

Associativity of & and | #14

Open junosuarez opened 10 years ago

junosuarez commented 10 years ago

Consider this signature: (Object)=>Boolean|(Object)=>Array<Boolean>

This would match one function with a return type of either Boolean or Array<Boolean>

Here, | is being used to match the complete function expression on either side. Would it be more clear to instead standardize on (Object)=>Boolean|Array<Boolean>, with the | operating on the most proximate type?

Raynos commented 10 years ago

I read (Object)=>Boolean|(Object)=>Array<Boolean> as object to return Boolean or function

I would express what you want as (Object)=>Boolean|Array<Boolean>

Raynos commented 10 years ago

I wrote this again

Any | (SendObject<Any> & {
    pretty?: Boolean,
    space?: String,
    replace?: Function
})

I used brackets to make it clear, but I think | goes first, then &

See https://github.com/Raynos/send-data/blob/master/docs.mli#L13