Skip to content

Commit

Permalink
feat(code-gen): pretty react-query hook types
Browse files Browse the repository at this point in the history
This improves the pop-overs in IDE's on what properties are accepted.
  • Loading branch information
dirkdev98 committed May 29, 2023
1 parent 8b30aba commit 7c644dc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/code-gen/src/api-client/react-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export function reactQueryGenerateCommonFile(generateContext) {
importCollector.destructure("react", "PropsWithChildren");
importCollector.destructure("react", "useContext");

fileWrite(file, `export type Pretty<T> = { [K in keyof T]: T[K] } & {};`);

if (distilledTargetInfo.isAxios) {
importCollector.destructure("axios", "AxiosInstance");

Expand Down Expand Up @@ -126,6 +128,8 @@ export function reactQueryGetApiClientFile(generateContext, route) {
const distilledTargetInfo = apiClientDistilledTargetInfo(generateContext);
const importCollector = JavascriptImportCollector.getImportCollector(file);

importCollector.destructure("../common/api-client-wrapper", "Pretty");

if (distilledTargetInfo.useGlobalClients) {
// Import the global clients, this has affect on a bunch of the generated api's where we don't have to accept these arguments
if (distilledTargetInfo.isAxios) {
Expand Down Expand Up @@ -290,10 +294,10 @@ export function reactQueryGenerateFunction(
if (requiredKeys.length > 0 && !requireAllParams) {
// We can just wrap it in an Partial which makes all required keys optional instead of writing them all out

return `Partial<${result}>`;
return `Pretty<Partial<${result}>>`;
}

return result;
return `Pretty<${result}>`;
};

const parameterListWithExtraction = ({
Expand Down

0 comments on commit 7c644dc

Please sign in to comment.