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

Testing type error #706

Closed
bryanjtc opened this issue Oct 24, 2024 · 6 comments · Fixed by #712
Closed

Testing type error #706

bryanjtc opened this issue Oct 24, 2024 · 6 comments · Fixed by #712
Labels
bug Something isn't working released

Comments

@bryanjtc
Copy link

bryanjtc commented Oct 24, 2024

Context

What's your version of nuqs?

v2.0.4

What framework are you using?

  • ✅ React Router

Which version of your framework are you using?

6.27.0

Description

I'm following the testing example https://nuqs.47ng.com/docs/testing and typescript throws the following errors.

Type '[UrlUpdateEvent]' does not satisfy the constraint 'Procedure'.
  Type '[UrlUpdateEvent]' provides no match for the signature '(...args: any[]): any'
Type 'Mock<[UrlUpdateEvent]>' is not assignable to type '(event: UrlUpdateEvent) => void'.
  Types of parameters 'args' and 'event' are incompatible.
    Type '[event: UrlUpdateEvent]' is not assignable to type 'never'

Reproduction

Follow the testing example
If needed use this tsconfig

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "verbatimModuleSyntax": false,
    "incremental": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["./*"]
    }
  },
  "references": [
    {
      "path": "./tsconfig.node.json"
    }
  ]
}

tsconfig.node.json

{
  "compilerOptions": {
    "composite": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "allowSyntheticDefaultImports": true
  },
  "include": ["vite.config.ts", "i18next.d.ts", "change-case.d.ts"]
}
@bryanjtc bryanjtc added the bug Something isn't working label Oct 24, 2024
@franky47
Copy link
Member

franky47 commented Oct 25, 2024

Thanks for the report.

What version of Vitest are you using?

@bryanjtc
Copy link
Author

bryanjtc commented Oct 25, 2024

Thanks for the report.

What version of Vitest are you using?

2.1.3

@franky47
Copy link
Member

Thanks, I managed to reproduce it here: https://github.com/franky47/nuqs-repro-706

I'll have a look, I see that I'm using Vitest 1 in the nuqs repository, it could be a breaking change on their part.

@franky47
Copy link
Member

franky47 commented Oct 25, 2024

Ok so the generic types for vi.fn have changed from listing the arguments and return types separately (PR vitest-dev/vitest#4784), to passing the type of the actual function.

So for Vitest 2 you should change the onUrlUpdate spy definition to:

const onUrlUpdate = vi.fn<(event: UrlUpdateEvent) => void>()

@bryanjtc
Copy link
Author

That solves it. Tk

@franky47
Copy link
Member

🎉 This issue has been resolved in version 2.1.0 🎉

The release is available on:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants