Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@openapi-codegen/typescript > 9.2.0 results into: 'This overload signature is not compatible with its implementation signature.' #294

Open
nyvid opened this issue Feb 11, 2025 · 1 comment

Comments

@nyvid
Copy link

nyvid commented Feb 11, 2025

Having the following example schema:

{
  "openapi": "3.1.0",
  "info": { "title": "sr-server", "version": "0.0.0" },
  "paths": {
    "/account/me": {
      "get": {
        "operationId": "get_current_account",
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Account" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Account": {
        "type": "object",
        "required": ["id", "iamId", "createdAt", "changedAt", "version"],
        "properties": {
          "changedAt": { "type": "string", "format": "date-time" },
          "createdAt": { "type": "string", "format": "date-time" },
          "iamId": { "type": "string" },
          "id": { "type": "string", "format": "uuid" },
          "username": { "type": ["string", "null"] },
          "version": { "type": "string", "format": "uuid" }
        }
      }
    }
  }
}

Generated the following components code:

/**
 * Generated by @openapi-codegen
 *
 * @version 0.0.0
 */
import * as reactQuery from "@tanstack/react-query";
import { ApiContext, queryKeyFn, useApiContext } from "./apiContext";
import type * as Fetcher from "./apiFetcher";
import { apiFetch } from "./apiFetcher";
import type * as Schemas from "./apiSchemas";
import { deepMerge } from "./apiUtils";

type QueryFnOptions = {
  signal?: AbortController["signal"];
};

export type GetCurrentAccountError = Fetcher.ErrorWrapper<undefined>;

export type GetCurrentAccountVariables = ApiContext["fetcherOptions"];

export const fetchGetCurrentAccount = (variables: GetCurrentAccountVariables, signal?: AbortSignal) =>
  apiFetch<Schemas.Account, GetCurrentAccountError, undefined, {}, {}, {}>({
    url: "/account/me",
    method: "get",
    ...variables,
    signal,
  });

export function getCurrentAccountQuery(variables: GetCurrentAccountVariables): {
  queryKey: reactQuery.QueryKey;
  queryFn: (options: QueryFnOptions) => Promise<Schemas.Account>;
};

export function getCurrentAccountQuery(variables: GetCurrentAccountVariables | reactQuery.SkipToken): {
  queryKey: reactQuery.QueryKey;
  queryFn: ((options: QueryFnOptions) => Promise<Schemas.Account>) | reactQuery.SkipToken;
};

export function getCurrentAccountQuery(variables: GetCurrentAccountVariables | reactQuery.SkipToken) {
  return {
    queryKey: queryKeyFn({
      path: "/account/me",
      operationId: "getCurrentAccount",
      variables,
    }),
    queryFn:
      variables === reactQuery.skipToken
        ? reactQuery.skipToken
        : ({ signal }: QueryFnOptions) => fetchGetCurrentAccount(variables, signal),
  };
}

export const useSuspenseGetCurrentAccount = <TData = Schemas.Account>(
  variables: GetCurrentAccountVariables,
  options?: Omit<
    reactQuery.UseQueryOptions<Schemas.Account, GetCurrentAccountError, TData>,
    "queryKey" | "queryFn" | "initialData"
  >,
) => {
  const { queryOptions, fetcherOptions } = useApiContext(options);
  return reactQuery.useSuspenseQuery<Schemas.Account, GetCurrentAccountError, TData>({
    ...getCurrentAccountQuery(deepMerge(fetcherOptions, variables)),
    ...options,
    ...queryOptions,
  });
};

export const useGetCurrentAccount = <TData = Schemas.Account>(
  variables: GetCurrentAccountVariables | reactQuery.SkipToken,
  options?: Omit<
    reactQuery.UseQueryOptions<Schemas.Account, GetCurrentAccountError, TData>,
    "queryKey" | "queryFn" | "initialData"
  >,
) => {
  const { queryOptions, fetcherOptions } = useApiContext(options);
  return reactQuery.useQuery<Schemas.Account, GetCurrentAccountError, TData>({
    ...getCurrentAccountQuery(deepMerge(fetcherOptions, variables)),
    ...options,
    ...queryOptions,
  });
};

export type QueryOperation = {
  path: "/account/me";
  operationId: "getCurrentAccount";
  variables: GetCurrentAccountVariables | reactQuery.SkipToken;
};

Typescript reports the following error:

This overload signature is not compatible with its implementation signature.ts(2394)
apiComponents.ts(39, 17): The implementation signature is declared here.

On version 9.2.0 everything works fine

@fabien0102
Copy link
Owner

fabien0102 commented Feb 17, 2025

The version 10 has some breaking changes (this is why the major version was bumped), you need to regenerate the fetcher, utils and context (and adapt them to your usecase).

Since those files are own by the users (only generated if they are not existing) it’s a bit tricky to migrate them automatically.

I will work a migration guide ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants