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

IntelliSense with types of JSDoc #7428

Closed
egamma opened this issue Mar 8, 2016 · 12 comments
Closed

IntelliSense with types of JSDoc #7428

egamma opened this issue Mar 8, 2016 · 12 comments
Assignees
Labels
Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue

Comments

@egamma
Copy link
Member

egamma commented Mar 8, 2016

From @anseki on March 8, 2016 4:25

I tried this:

/**
 * @param {string} param1 - Normal
 * @param {string|number|boolean} param2 - Multiple types
 * @param {null} param3 - (I know this is strange param.)
 * @param {string|number|null} param4 - Multiple types includes `null`
 * @param {Object} param5 - Object type
 * @param {Array} param6 - Array type
 * @param {jQuery} param7 - Another type
 * @param {MyClass} param8 - Another type
 * @param {string|number|Array} param9 - Multiple types includes `Array`
 * @param {?string} param10 - Nullable type
 * @param {string} [param11] - Optional
 * @returns {?string} result
 */
function fnc(param1, param2, param3, param4, param5, param6,
    param7, param8, param9, param10, param11) {
  return param11;
}

fnc();
  • param3: any, param4: any, param6: any, param7: any, param8: any, param9: any
  • param10: string

It seems that:

  • The type of @param that includes null, Array, and other classes other than Object are shown as any.
  • The optional params are shown with ?, but nullable params and returns are shown with nothing.

I hope that the specified types are shown even if that is null, Array, or unknown type such as jQuery or MyClass. And nullable params are shown like optional params.

Copied from original issue: microsoft/vscode#3802

@egamma
Copy link
Member Author

egamma commented Mar 8, 2016

moving to TypeScript

@RyanCavanaugh
Copy link
Member

As for nullability, this is by design. Nullable parameters aren't the same as optional, and T | null won't be valid syntax until nullable types become available in TypeScript.

For Array we need to special-case this (we expected to see Array<T>)

@RyanCavanaugh RyanCavanaugh self-assigned this Mar 8, 2016
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 2.0 milestone Mar 8, 2016
@DanielRosenwasser
Copy link
Member

@RyanCavanaugh I think the special case should be general enough for all generic types - perhaps instantiating with with any for all type arguments.

@Thaina
Copy link

Thaina commented Mar 9, 2016

I too think null is not type. It is value. You need to set type as {boolean | number} not {true | number}. Same go for null, you could set it as string or any

As for nullable it is {?any}

For {Array} is should be just like {[]}

@anseki
Copy link

anseki commented Mar 9, 2016

Yes I know null or undefined are value.
But some style guide such as Google JavaScript Style Guide specifies null in JSDoc to indicate the param that might be multiple type and null.
If the param accepts something type and null, it can be {?somethingType}. But if it accepts more types and null, no notation for "multiple && nullable".

@anseki
Copy link

anseki commented Mar 9, 2016

Sorry, I don't understand the mechanism of IntelliSense. Is showing specified text as type difficult? even if that is unknown type such as jQuery or DOM element or MyClass.

@anseki
Copy link

anseki commented Mar 9, 2016

I think that this issue is solved if IntelliSense parses @typedef or @class. Those tags might be able to deceive IntelliSense. (It make also a source code dirty.)
Or, as I said, it is solved if IntelliSense shows specified text as type.

I think that null is needed by current version of JSDoc to indicate an optional param that is not positioned at the end of params list because It don't have syntax to indicate that now. http://usejsdoc.org/tags-type.html
Then, some style guides such as Google specify null.
Also, types such as Array, jQuery, DOM element or MyClass are typically used in JS.
Those should be shown. Because JSDoc is used for documentation or some guide, JSDoc is not a tool to check syntax like debugger.
We don't want to write @class and something for jQuery in to all source code.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 17, 2016

With nullable types in, we should add logic to handle ?T and !T.

@mhegazy mhegazy added the Suggestion An idea for TypeScript label Mar 17, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.1, TypeScript 2.0 Jun 6, 2016
@waderyan waderyan added the VS Code Tracked There is a VS Code equivalent to this issue label Sep 14, 2016
@mhegazy mhegazy modified the milestones: Future, TypeScript 2.1 Sep 29, 2016
@mhegazy mhegazy added the Domain: JSDoc Relates to JSDoc parsing and type generation label Dec 15, 2016
@Jessidhia
Copy link

null and undefined are now supported when "strictNullChecks": true is enabled in the jsconfig.json. jsdoc nullable syntax isn't, though.

@ghost
Copy link

ghost commented Mar 3, 2017

i hope i'm in the right place

is there no support for typing callbacks this way or am i just doing it all wrong?

fun1
fun2

i'm using the latest version of vs code

@Jessidhia
Copy link

You can, but at least for simple cases (no union types, not inside another type) you have to use closure compiler syntax. Something like {function(string, string): void} (note: no parameter names possible)

@mhegazy
Copy link
Contributor

mhegazy commented Aug 31, 2017

These should be working now as described in the OP.

@mhegazy mhegazy closed this as completed Aug 31, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Aug 31, 2017
@mhegazy mhegazy modified the milestones: TypeScript 2.6, Future Aug 31, 2017
@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
Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests

8 participants