How do I annotate a generic function inside an object?
UtkarshVerma opened this issue · comments
I have the following typedef
:
/**
* @template T
* @typedef {Object} QuickAddApi
* @property {(header: string, placeholder?: string, value?: string) => Promise<string>} inputPrompt
* @property {function(string[], T[]): T} suggester
*/
My intent here is to let the LSP server know that the param and return types are bound for suggestor
. However, using the type QuickAddApi
forces me to specify a type using QuickAddApi<string>
. Can I somehow specify the generic only for the function and not the entire object?
You can't instantiate an instance of QuickAddApi
without knowing the type of suggester
so I would say that passing the generic argument to QuickAddApi
is the way to go.
But this is not a question specific to this server but rather to Typescript itself so I would suggest asking such questions on Stack Overflow, for example.