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

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

Closed
helt opened this issue Aug 31, 2024 · 5 comments · Fixed by #1183
Closed

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

helt opened this issue Aug 31, 2024 · 5 comments · Fixed by #1183
Assignees
Labels
bug Something isn't working @kubb/plugin-swr v2 v3 Kubb v3

Comments

@helt
Copy link
Contributor

helt commented Aug 31, 2024

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 #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 helt added the bug Something isn't working label Aug 31, 2024
@helt
Copy link
Contributor Author

helt commented Aug 31, 2024

#1176

@stijnvanhulle
Copy link
Collaborator

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
Copy link
Contributor Author

helt commented Sep 1, 2024

{
  "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
Copy link
Collaborator

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 stijnvanhulle linked a pull request Sep 22, 2024 that will close this issue
1 task
@stijnvanhulle
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working @kubb/plugin-swr v2 v3 Kubb v3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants