0

I am documenting a set of GraphQL-based APIs, which all return a response of similar structure.
I have a @typedef with @template parameters to document these, which looks like this:

/**
 * @template DataType
 * @typedef {Promise<{
 *  data: DataType | null,
 *  errors: ReadonlyArray<GQLErrorObject>
 * }>} GQLResponse
 */

And then, I type the API @return like this:

/*
 * @return {GQLResponse<{ project_createNew: Project | null }>}
 */

But I have many such APIs, and I was wondering if it was possible to @template-ify the project_createNew key name? So, for example, if I have the API project_downloadReport, I would like to be able to type it something like this:

/*
 * @returns {GQLResponse<"project_downloadReport", PDFFileData}>}
 */

Is this possible at all?

cristian
  • 866
  • 3
  • 8
  • 26

0 Answers0