-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSDoc: function declarations are not type checked #16250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In my opinion, function declarations can't use the declare const foo: (x: number) => number;
declare function foo2(x: number): number; You can't use type declaration for function declaration, you have to use {
/** @type {function (number): number} */
const foo = (x) => x
foo('f') // error, good!
/**
* @param {number} x
* @return {number}
*/
function foo2(x) { return x }
foo2('f') // error, as expected
} |
@ikatyang Interesting, how would you add a property to a function declaration? I've tried using /**
* @param {number} x
* @property {number} bar
* @return {number}
*/
function foo2(x) { return x }
foo2('f') // error, as expected
foo2.bar = 1; // unexpected error |
@ikatyang I think what you're seeing is related to a different bug with JSDoc: #16239 (comment) If you wrap that code in a block, it will give you the unexpected error: {
/**
* @param {number} x
* @return {number}
*/
function foo2(x) { return x }
foo2('f') // error, as expected
foo2.bar = 1; // unexpected error
}
{
/**
* @param {number} x
* @property {number} bar
* @return {number}
*/
function foo2(x) { return x }
foo2('f') // error, as expected
foo2.bar = 1; // unexpected error
} |
I think the only way to add a property to a function is using variable declaration, since you can't define a function type mixin with something else. /**
* @type {{ (x: number): string, bar: number }}
* @param {number} x
* @return {number}
**/
var foo2 = function (x) { return x };
foo2.bar = 1; And for the
|
Thanks. I think your original conclusion was right. I can't find of any way to do this in |
TypeScript Version: 2.3.4
Code
The text was updated successfully, but these errors were encountered: