Skip to content
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

Optional parameters indicated via JSDoc are not respected #8734

Closed
mihaip opened this issue May 21, 2016 · 1 comment
Closed

Optional parameters indicated via JSDoc are not respected #8734

mihaip opened this issue May 21, 2016 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created

Comments

@mihaip
Copy link

mihaip commented May 21, 2016

TypeScript Version: nightly (1.9.0-dev.20160521) (same behavior in 1.8.10).

Given this plain JavaScript file annotated with JSDoc for the Closure Compiler (included via allowJs):

/**
 * @param {number=} input
 * @return {number}
 */
function legacyMethod(input) {
    if (typeof input === "undefined") {
        return 0;
    }
    return input * input;
};

And this TypeScript file:

console.log(legacyMethod(1));
console.log(legacyMethod());

I would expect that the second legacyMethod call to also be fine, due to the = suffix on the type (see https://developers.google.com/closure/compiler/docs/js-for-compiler#types for more details on the Closure Compiler type language). Based on Visual Studio Code's Intellisense the extracted type for legacyMethod is function legacyMethod(input?: number): number which seems correct. However, when running, I get:

main.ts(2,13): error TS2346: Supplied parameters do not match any signature of call target.

Out of curiosity, I tried legacyMethod(undefined) which worked (as did legacyMethod(null), which the Closure Compiler would not have allowed, since optional parameters are undefined, not null).

@mhegazy mhegazy added the Bug A bug in TypeScript label Jun 7, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Jun 7, 2016
@mhegazy mhegazy added the Salsa label Jun 7, 2016
@sandersn sandersn added the Duplicate An existing issue was already created label Jun 10, 2016
@sandersn
Copy link
Member

Duplicate of #6992 -- that bug also has some interesting discussion about what to do in the case that we still can't find a matching signature.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants