Description
TypeScript Version: 3.7.x-dev.20200109
Search Terms:
JSDoc callback nested parameter
Code
Our SDK is written in Javascript, compiled with respect ES2015 and uses the following JSDoc construct with success to generate API reference. We make heavy use of user-supplied callbacks and we let users take advantage of Object destructuring in the parameter list.
I am trying to enable our Typescript consumers to leverage autocompletion and type-checking in conjunction with our SDK and make their lives easier.
/**
* @callback WorksWithPeopleCallback
* @param {Object} person
* @param {String} person.name
* @param {Number} [person.age]
* @returns {void}
*/
/**
* For each person, calls your callback.
* @param {WorksWithPeopleCallback} callback
* @returns {Promise<void>}
*/
function eachPerson(callback) {
}
Expected behavior:
declare function eachPerson(callback: WorksWithPeopleCallback): Promise<void>;
type WorksWithPeopleCallback = (person: { name: string, age?: number }) => void;
Actual behavior:
declare function eachPerson(callback: WorksWithPeopleCallback): Promise<void>;
type WorksWithPeopleCallback = (person: any, name: string, age?: number) => void;
In my opinion, this is a bug, though a subtle one.
Nested parameter types are ignored by a condition parser.ts (https://github.com/microsoft/TypeScript/blob/v3.7.4/src/compiler/parser.ts#L7041). I tried to recompile tsc
after removing the condition and it seems to work fine.
Before I submit the PR, please explain if there is a reason for this feature being deliberately disabled.
It works for sure in pure Typescript: https://www.typescriptlang.org/play/#code/C4TwDgpgBAwghgGwQIzgYwNZQLxQBSQBOAzgPYB2AXFAN5TlwC2E1xwhAluQOYA0UcbhAD81cgFdGyCISgBfAJQ4AfFABupDgBMA3ACg9AM3Hk0wDhShhCpNBGLE8aRCnQZq8JKkxKaeqAFQzl5ueHQMzNQARHBR8gr6ckA