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

Allow custom object types in JSDoc #9276

Closed
dbaeumer opened this issue Jun 20, 2016 · 5 comments
Closed

Allow custom object types in JSDoc #9276

dbaeumer opened this issue Jun 20, 2016 · 5 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@dbaeumer
Copy link
Member

From @Grim2d on June 18, 2016 10:11

I'm using "vanilla" javascript for development. If I write custom object type in JSDoc, it appears as any or void . It will be more helpful, if one can type custom types.

  • VSCode Version: 1.1.1 (1.1.1)
  • OS Version: OSX (10.11.4)

Steps to Reproduce:
1.

/**
 * @param document {Object}
 * @returns {Object}
 */
function addDocument(document) {

}

screen shot 2016-06-18 at 3 07 53 pm
1.

/**
 * @param document {ProductProjection}
 * @returns {ObjectId}
 */
function addDocument(document) {

}

screen shot 2016-06-18 at 3 07 15 pm

Copied from original issue: microsoft/vscode#7847

@dbaeumer
Copy link
Member Author

Moving to TS team.

@zhengbli
Copy link
Contributor

zhengbli commented Jul 8, 2016

With nightly you can defined customized type using the @typedef tag, for example

/**
 * @typedef { {name: string, age: number} } People
 */

Then use it elsewhere in jsdoc.

And with #9546, you can use the @callback tag alternatively as well.

@zhengbli zhengbli added the Question An issue which isn't directly actionable in code label Jul 8, 2016
@GRiMe2D
Copy link

GRiMe2D commented Jul 10, 2016

Trying to write type definitions according #8103

Format 3 doesn't work properly

/**
 * @typedef {Object} Product
 * @property {String} name
 */

/**
 * Creates a product instance
 * @return {Product}
 */
function makeProduct() {}

screen shot 2016-07-10 at 9 14 20 pm


However format 1 works

/**
 * @typedef {{name: String}} Product
 */

/**
 * Creates a product instance
 * @return {Product}
 */
function makeProduct() {}

screen shot 2016-07-10 at 9 14 48 pm


$ tsc -v
Version 2.0.0-dev.20160707

@GRiMe2D
Copy link

GRiMe2D commented Jul 10, 2016

Also, function declarations are required.

Something like:

/**
 * @typedef {{name: String, workClosure: () => (Error, Date) => void}} Product
 */

@zhengbli
Copy link
Contributor

@Grim2d That's a bug, I'll send a fix soon, it should have worked.

Regarding the function type, we use the popular jsdoc notation instead, so to achieve what you want you can do:

/**
 * @typedef { {name: String, workClosure: function(): function(Error, Date): void} } Product
 */

Reference for the type expression pattern:
https://developers.google.com/closure/compiler/docs/js-for-compiler#types

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants