Can't this be implemented as a DSL? https://gist.github.com/1180516
guardArgs = (def, args) ->
i = 0
for arg, type of def
throw new Error("bad type of #{arg}") unless typeof args[i] == type
i++
typeEnsure = (def, f) -> ->
guardArgs(def, arguments)
f.apply @, arguments
myFunc = typeEnsure {name: 'string', i: 'number'}, (name, i) ->
console.log name, i
myFunc("foo", 1) # ok
myFunc("foo", "x") # Error: bad type of i
I think this can be extended to custom types too.