Skip to content

Instantly share code, notes, and snippets.

@bwindels
Created January 29, 2020 15:39
Show Gist options
  • Save bwindels/11be14ba1964b69f7839adabd766d065 to your computer and use it in GitHub Desktop.
Save bwindels/11be14ba1964b69f7839adabd766d065 to your computer and use it in GitHub Desktop.
use typescript to check javascript types with jsdoc annotations
// check with tsc --allowJs --checkJs --noImplicitAny --noEmit --lib ES2017,dom test.js
/**
* @param {Number} a operand 1
* @param {Number} b operand 2
* @return Promise<Number>
*/
async function add(a, b) {
return a + b;
}
/**
@typedef Foo
@property {(n: Number) => void} bar
*/
/**
* @param {Foo} foo
*/
function dofoo(foo) {
foo.bar(5);
}
/**
* @param {Object} options
* @param {Number} options.c
*/
function printit({c}) {
console.log(c);
}
(async function() {
printit({c: await add(5, 3)});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment