Skip to content

Instantly share code, notes, and snippets.

@mason-stewart
Created December 21, 2013 17:06
Show Gist options
  • Save mason-stewart/8072095 to your computer and use it in GitHub Desktop.
Save mason-stewart/8072095 to your computer and use it in GitHub Desktop.
Typed functions in Sweet.js
let function = macro {
rule {
$fn ($($arg ":"$type) (,) ...) $body
} => {
function $fn ($($arg) ...) {
if ($(typeof($arg) == $type &&) ...) {}
$($type) (,)...
}
}
}
function coolGuy (a :string, b :number) {
return 'ya turkey'
}
coolGuy(1, []); // should fail
coolGuy('yay', 4); // should pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment