swagger-typescript-codegen
swagger-typescript-codegen copied to clipboard
[feature] concise response type alias
The response types can be quite long, and inconvenient to use.
const x: Promise<ResponseWithBody<200, OkBody> | ResponseWithBody<404, NotFoundBody> | ResponseWithBody<400, BadRequestBody>> = undefined;
I propose generating some concise type aliases.
type SomeAlias1 = ResponseWithBody<200, OkBody>;
type SomeAlias2 = ResponseWithBody<404, NotFoundBody>;
type SomeAlias3 = ResponseWithBody<400, BadRequestBody>;
type SomeUnionResponseAlias = SomeAlias1 | SomeAlias2 | SomeAlias3;
The alias's should be backwards compatible, optional to use and work as drop in replacements.
Hi Scott,
I really like the idea.
Just to clarify, when you say optional you mean you would like like to be able to control if they are generated or not?
Just to clarify, when you say optional you mean you would like like to be able to control if they are generated or not?
My original intent was "optional to use" the aliases.
Typescript type definitions are only used at compile time, and there is no additional code generated in the output .js file. So I can't think of any drawbacks of always generating these additional types. Would be up-to the developer to decide which types they want to import and use.
Really like this idea as well! Ensuring we export both the verbose and the consise types would make them optional to use as well. Should not cause any bundle size issues either for the consumer, as as you mention these are just compile time types
@scottc - Wanna give this a shot?