Created
January 29, 2020 15:39
-
-
Save bwindels/11be14ba1964b69f7839adabd766d065 to your computer and use it in GitHub Desktop.
use typescript to check javascript types with jsdoc annotations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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