Here is some code (simplified) to understand better:
A wrapper to send requests
- It does some common things when the request is sent and when it is completed.
- It returns the result of the request (handler).
async function request (handler) {
// common stuff
try {
const result = await handler()
return result || true
}
catch (err) {
doSomethingWithError(err)
return err
}
finally {
// common stuff
}
}
/**
* Imagine a simple service / api client
*/
const someApiClient = {
/**
* @returns {Promise<string[]>} 3 first letters
*/
async getSomeData () {
return ['a', 'b', 'c']
}
}
/**
* Just a function or method using the api client, that has types declared
*/
async function fetchMeSomeDataHandler () {
return someApiClient.getSomeData()
}
const result = await request(() => fetchMeSomeDataHandler())
Expected
Here, I would expect vscode / jsdoc to infer that the type of "result" is string[] and even give me the description from the api client ("3 first letters").
But it isn't, it will give a type of any at the end.
What we get in vscode
If we follow the types picked up by vscode, we can see it's "losing the types little by little" until there is nothing left.
- Full type description picked up for the api client.
- The type is known in the handler definition but we lost the client value description (3 first letters).
- We lost the type information completely for the final result



