question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include resolve type in API documentation for Promise return types

See original GitHub issue

The API documentation for functions that use promises list Promise as the return type for the function (e.g. documentation for DS.Store.findAll). While technically correct, this is nearly useless from a documentation perspective, since it doesn’t tell you what type the promise resolves to.

This becomes more noticeable when using the async/await syntax, where the promise gets hidden behind the scenes. For example:

let records = await store.findAll('users');

There’s nothing in the documentation to indicate what the type of records is.

To improve the usability of the documentation, I propose including the type of the resolved value of the Promise in the @return tag so it appears in the generated API docs.

One syntax would be to use the same syntax as generics, so to indicate that the promise resolves to a DS.Model object, the JSDocs would be:

/**
 * @return {Promise<DS.Model>} a promise which returns a single instance of the model`
 */

Which would then allow the API docs to show Promise<DS.Model> as the return type.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
pixelhandlercommented, Apr 7, 2017

@fastfedora if you have any questions about Ember Data, @skaterdav85 wrote a great book on the subject 😃

0reactions
Serabecommented, Jul 13, 2017

Fixed in #15316. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to specify resolution and rejection type of the promise in ...
I have some code that returns a promise object ...
Read more >
Promise.resolve() - JavaScript - MDN Web Docs
The Promise.resolve() method "resolves" a given value to a Promise . If the value is a promise, that promise is returned; if the...
Read more >
Documenting promise return types · Issue #63 · microsoft/tsdoc
JsDoc has been discussing how to document Promise return types for some time. Does tsdoc have any plans to support @resolves and @rejects ......
Read more >
Promise API - The Modern JavaScript Tutorial
Promise.all takes an iterable (usually, an array of promises) and returns a new promise. The new promise resolves when all listed promises ......
Read more >
Learn How does TypeScript Promise type work? - eduCBA
Promise accepts a callback function as parameters, and in turn, the callback function accepts two other parameters, resolve and reject. If the condition...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found