4 ms·
That's not entirely accurate. TypeScript 1.8 added the ability to use type information from JSDoc-style comments. For example: /** * @param {string}
by joshuacc 10y ago
That's not entirely accurate. TypeScript 1.8 added the ability to use type information from JSDoc-style comments.
For example:
/**
* @param {string} a
* @param {number} b
* @returns {string}
*/
function foo(a, b){
return a + b;
}
Is functionally identical to:
function foo(a: string, b: number): string {
return a + b;
}
See: https://github.com/Microsoft/TypeScript/issues/4790 https://github.com/Microsoft/TypeScript/issues/4790
- Arnavion 10y agoNot equivalent - the TS compiler currently does not actually enforce the types in a JS file. See https://github.com/Microsoft/TypeScript/issues/4790#issuecomment-220807667 https://github.com/Microsoft/TypeScript/issues/4790#issuecom... The feature of parsing JSDoc comments is currently only used for providing completion info for JS editors and for consuming exported JS functions and variables in TS files.
- joshuacc 10y agoAh, you're right. Looks like I'd misunderstood the scope of that change.
- abritinthebay 10y ago"functionally" identical to the type checker. But not functionally identical when it involves my fingers typing (the function there being my ergonomics). Flow would just be inline comments at the code points required.