hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.39k stars 107 forks source link

react query plugin not playing well with client-fetch options #1256

Open nutrian opened 1 week ago

nutrian commented 1 week ago

Description

Lots of type errors in the generated react-query.gen.ts

import type { Options } from '@hey-api/client-fetch';

type QueryKey<TOptions extends Options> = [
    Pick<TOptions, 'baseUrl' | 'body' | 'headers' | 'path' | 'query'> & {
        _id: string;
        _infinite?: boolean;
    }
];
type OptionsBase<ThrowOnError extends boolean> = Omit<RequestOptionsBase<ThrowOnError>, 'url'> & {
    /**
     * You can provide a client instance returned by `createClient()` instead of
     * individual options. This might be also useful if you want to implement a
     * custom client.
     */
    client?: Client;
};
type Options<T = unknown, ThrowOnError extends boolean = boolean> = T extends {
    body?: any;
} ? T extends {
    headers?: any;
} ? OmitKeys<OptionsBase<ThrowOnError>, 'body' | 'headers'> & T : OmitKeys<OptionsBase<ThrowOnError>, 'body'> & T & Pick<OptionsBase<ThrowOnError>, 'headers'> : T extends {
    headers?: any;
} ? OmitKeys<OptionsBase<ThrowOnError>, 'headers'> & T & Pick<OptionsBase<ThrowOnError>, 'body'> : OptionsBase<ThrowOnError> & T;

Resulting errors

Type 'string' does not satisfy the constraint 'keyof TOptions'.
  Type 'string' is not assignable to type 'keyof TOptions'.
    Type '"body"' is not assignable to type '"method" | "cache" | "credentials" | "integrity" | "keepalive" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window" | "path" | "query" | "baseUrl" | ... 6 more ... | "client"'.ts(2344)

Reproducible example or configuration

Can't reproduce the error on stackblitz, no idea why.... tried aligning typescript and hey-api package versions on stackblitz as my local machine, just works on stackblitz for some reason

node 18.16.1 typescript 5.4.5 @hey-api/client-fetch 0.4.2 @hey-api/openapi-ts 0.54.0

OpenAPI specification (optional)

No response

System information (optional)

No response

mrlubos commented 1 week ago

@nutrian can you provide versions of all relevant packages?

nutrian commented 1 week ago

node 18.16.1 typescript 5.4.5 @hey-api/client-fetch 0.4.2 @hey-api/openapi-ts 0.54.0