I have observed some issues when declaring a function with generics related to some parameters.
Just figure out a type defined like this:
interfaces Response { type: string; data: T }
interface Doc { body: string; }
And we want use like this case:
/**@type {ResponseFunc<Doc>}*/
function handler(response){ // <-- intellisense type have to be 'Response<Doc>'
response.data <-- intellisense type have to be 'Doc'
...code...
}
If ResponseFunc<T> is defined like function:
declare function ResponseFunc<T>(Response<T>):void; // as classic function
type ResponseFunc = <T>(res: Response<T>): void; // as arrow function
Type of parameter is shown like Response<T>. Generic type is not resolved.
If ResponseFunc<T> is defined like type object:
type ResponseFunc<T> = {
function(Response<T>) : void;
}
Generic is resolved but parameter is show as any instead of Doc.
We need to merge this two ways to resolve the generic type and show parameter with right type.
type ResponseFunc<T> = {
(response: Response<T>) : void;
}