kubb-labs / kubb

The ultimate toolkit for working with APIs.
https://kubb.dev
MIT License
713 stars 62 forks source link

swr mutations with pathParams results in type errors on mutation #1177

Closed helt closed 1 month ago

helt commented 2 months ago

What version of kubb is running?

No response

What platform is your computer?

wsl

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

No response

What steps can reproduce the bug?

see freshly added oas as in https://github.com/kubb-labs/kubb/pull/1176

generated code: image

Details about the issue on mutationOptions:

No overload matches this call.
  Overload 1 of 3, '(key: `/api/datasets/${string}/content/data/aligned_values` | null, fetcher: (key: `/api/datasets/${string}/content/data/aligned_values`, options: Readonly<{ arg: never; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>, options?: SWRMutationConfiguration<...> | undefined): SWRMutationResponse<...>', gave the following error.
    Argument of type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError> | undefined' is not assignable to parameter of type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError, `/api/datasets/${string}/content/data/aligned_values` | null, never, ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse> | undefined'.
      Type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError>' is not assignable to type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError, `/api/datasets/${string}/content/data/aligned_values` | null, never, ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>'.
        Types of property 'fetcher' are incompatible.
          Type '((key: string, options: Readonly<{ arg: any; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>) | ((key: ArgumentsTuple, options: Readonly<...>) => FetcherResponse<...>) | ((key: Record<...>, options: Readonly<...>) => FetcherResponse<...>) | ((key: string | .....' is not assignable to type '((key: `/api/datasets/${string}/content/data/aligned_values`, options: Readonly<{ arg: never; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>) | undefined'.
            Type '(key: ArgumentsTuple, options: Readonly<{ arg: any; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>' is not assignable to type '(key: `/api/datasets/${string}/content/data/aligned_values`, options: Readonly<{ arg: never; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>'.
              Types of parameters 'key' and 'key' are incompatible.
                Type '`/api/datasets/${string}/content/data/aligned_values`' is not assignable to type 'ArgumentsTuple'.
  Overload 2 of 3, '(key: `/api/datasets/${string}/content/data/aligned_values` | null, fetcher: (key: `/api/datasets/${string}/content/data/aligned_values`, options: Readonly<{ arg: never; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>, options?: (SWRMutationConfiguration<...> & { ...; }) | undefined): SWRMutationResponse<...>', gave the following error.
    Argument of type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError> | undefined' is not assignable to parameter of type '(SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError, `/api/datasets/${string}/content/data/aligned_values` | null, never, ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse> & { ...; }) | undefined'.
      Type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError>' is not assignable to type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError, `/api/datasets/${string}/content/data/aligned_values` | null, never, ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse> & { ...; }'.
        Type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError>' is not assignable to type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError, `/api/datasets/${string}/content/data/aligned_values` | null, never, ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>'.
          Types of property 'fetcher' are incompatible.
            Type '((key: string, options: Readonly<{ arg: any; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>) | ((key: ArgumentsTuple, options: Readonly<...>) => FetcherResponse<...>) | ((key: Record<...>, options: Readonly<...>) => FetcherResponse<...>) | ((key: string | .....' is not assignable to type '((key: `/api/datasets/${string}/content/data/aligned_values`, options: Readonly<{ arg: never; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>) | undefined'.
              Type '(key: ArgumentsTuple, options: Readonly<{ arg: any; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>' is not assignable to type '(key: `/api/datasets/${string}/content/data/aligned_values`, options: Readonly<{ arg: never; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>'.
                Types of parameters 'key' and 'key' are incompatible.
                  Type '`/api/datasets/${string}/content/data/aligned_values`' is not assignable to type 'ArgumentsTuple'.
  Overload 3 of 3, '(key: `/api/datasets/${string}/content/data/aligned_values` | null, fetcher: (key: `/api/datasets/${string}/content/data/aligned_values`, options: Readonly<{ arg: never; }>) => FetcherResponse<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>, options?: (SWRMutationConfiguration<...> & { ...; }) | undefined): SWRMutationResponse<...>', gave the following error.
    Argument of type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError> | undefined' is not assignable to parameter of type '(SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError, `/api/datasets/${string}/content/data/aligned_values` | null, never, ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse> & { ...; }) | undefined'.
      Type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError>' is not assignable to type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError, `/api/datasets/${string}/content/data/aligned_values` | null, never, ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse> & { ...; }'.
        Type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError>' is not assignable to type 'SWRMutationConfiguration<ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse, HttpValidationError, `/api/datasets/${string}/content/data/aligned_values` | null, never, ReadValuesAlignedApiDatasetsDatasetIdContentDataAlignedValuesPostMutationResponse>'.

How often does this bug happen?

Every time

What is the expected behavior?

no squiggly lines :D

Swagger/OpenAPI file?

in PR

Additional information

No response

helt commented 2 months ago

1176

stijnvanhulle commented 2 months ago

What TypeScript version are you using and what does your tsconfig.json look like? I tried the same with our e2e setup and the code generated based on our own tsconfig.json seems valid, also which SWR version have you installed? Maybe there is a mismatch between their types and ours.

helt commented 2 months ago
{
  "compilerOptions": {
    "target": "es2015",
    "lib": ["dom", "dom.iterable", "esnext"],
    "types": ["node", "cypress", "jest"],
    "allowJs": true,
    "skipLibCheck": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "downlevelIteration": true,
    "alwaysStrict": true,
    "strict": true,
    "plugins": [
      {
        "name": "next",
      },
    ],
    "paths": {
      "@/*": ["./src/*"],
    },
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": [
    "node_modules",
    "cypress.config.ts",
    "cypress/",
    "**/__tests__/**/*.[tj]s?(x)",
    "**/*.{spec,test}.[tj]s?(x)",
  ],
}
stijnvanhulle commented 2 months ago

It seems that having strict is throwing some errors, something we don't have in the e2e tests. I will merge your pr and enable this on the e2e cases.

    "alwaysStrict": true,
    "strict": true
stijnvanhulle commented 1 month ago

@helt This has been fixed as part of the latest v3 alpha :) It took some time but finally have something that works for SWR.