Let's say I have a function whose return value is a defined typescript interface. The interface is well annotated:
interface ReturnValue {
/**
* Wind value, in knots
*/
wind: number;
/**
* Humidity in %
*/
humidity: number;
}
/**
* Function to return some values
* @returns Returner
*/
const myFunction = (): ReturnValue => {
return {
wind: 4,
humidity: 5
};
};
I'd like to be able to see the annotations of the return value interface when I use intellisense, or when hovering over the function. Instead, this is what I get:

I get a little more detail when I don't name the interface but declare it directly as the return value of the function:
/**
* Function to return some values
*/
const myFunction = (): {
/**
* Wind value, in knots
*/
wind: number;
/**
* Humidity in %
*/
humidity: number;
} => {
return {
wind: 4,
humidity: 5
};
};
This gives:

But even this doesn't the show comments I used when defining the return value object shape. Also its messy.
Is it possible to write JSDoc comments such that I can see them as part of the intellisense when defining return values in typescript?
Sadly, you don't really have any control here.
Typescript types can get deep, and completely unfolding all of them always to their atomic pieces isn't really practical for more complex types. But, as you note, for simple types it can be a bit too quick to wrap them up in a named alias. A tooltip that has many pages of interface details to scroll through is almost as useless as very little information.
So typescript errs on the side of conciseness, opting to show you the types you have named rather than large granular interfaces.
If you want to know what in a type like this, you can just make one, type a . and then explore its interface:

And the JS doc comments do make their way through when you actually use them:

Though I agree it can be hard to understand what's in a type sometimes, I don't believe there are any ways to manipulate how TypeScript/VSCode unravel and report on your type aliases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With