Closed Downchuck closed 1 week ago
This link is a great resource for actually getting aliases to show up when they sometimes don't in type hints in your IDE:
This one in particular will expand tuples, especially useful for return type:
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
For:
type myfunc = (myarg: number) => [col1: string, cold2: number, col3: string][]
export interface example {
myfunc(...args: Parameters<myfunc>): Promise<Expand<ReturnType<myfunc>>>
}
Again this is very VS Code hinting-oriented, but it was nice to see that interface work on an include. I'm in a JSDoc centric world so that's picked up in javascript file via:
/** @typedef {import("./api.d.ts").example} example */
/** @type {example} */
const exampleImpl = /** @type {const} */ {
async myfunc(myarg) {
return ...
}
}
Some extra const in there to allow more type testing to flow through.
Not sure what the use cases are here, do you want to have function that will be used by React-Query be typed as tuples or do you want to have tuples that are named(in our ts plugin)? Do you have an example(based on the Swagger/OpenApi Petstore) of what you want to see as result?
This will be resolved with https://github.com/kubb-labs/kubb/issues/1195
I would like named/labeled tuples support in play; https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#labeled-tuple-elements
These are poorly supported by OpenAPI by using min and max element counts for an array of values.
What is the problem this feature would solve?
Named tuples may be used for easier to read function parameters, or for other structured tuple data.
Example:
There are no utility functions in Typescript to support conversion from a struct:
What is the feature you are proposing to solve the problem?
Named parameters are usable for functions:
Named parameters are useful for tuples in an IDE,:
In Visual Studio Code, the
test
variable will hover with:(property) 0: number (id)
, as the type annotation carries through.While this is a request for an extra option on the swagger ts plugin to just export alongside the generated
Request
structure for json-body style inputs.What alternatives have you considered?
Request / Response pairs could be written out as a function:
OAS has Tuple support with a description field. It's a bit of a chore with min and max array lengths. Adding tuples to all input types could be a bit verbose, in trying to include query and path params.
This is intended as an optional feature, with the default of false.