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

jest-dom/types/matchers-standalone.d.ts:9:3 - error TS2300: Duplicate identifier 'toHaveClass'. #605

Open
aliu-vmware opened this issue Jun 11, 2024 · 4 comments

Comments

@aliu-vmware
Copy link

  • @testing-library/jest-dom version: 6.4.5
  • node version: 20.12.0
  • jest (or vitest) version: 29.7.0
  • npm (or yarn) version: 10.5.0

Relevant code or config:

What you did:

Tried to start up a storybook using a default angular project generated via ng new and ng generate library

What happened:

ERROR in node_modules/@testing-library/jest-dom/types/matchers-standalone.d.ts:9:3 - error TS2300: Duplicate identifier 'toHaveClass'.

9   toHaveClass: (expected: any, ...rest: string[]) => MatcherReturnType
    ~~~~~~~~~~~

ERROR in node_modules/@testing-library/jest-dom/types/matchers-standalone.d.ts:10:3 - error TS2300: Duplicate identifier 'toHaveClass'.

10   toHaveClass: (
     ~~~~~~~~~~~

ERROR in node_modules/@testing-library/jest-dom/types/matchers-standalone.d.ts:10:3 - error TS2717: Subsequent property declarations must have the same type.  Property 'toHaveClass' must be of type '(expected: any, ...rest: string[]) => MatcherReturnType', but here has type '(expected: any, className: string, options?: { exact: boolean; } | undefined) => MatcherReturnType'.

10   toHaveClass: (
     ~~~~~~~~~~~

  node_modules/@testing-library/jest-dom/types/matchers-standalone.d.ts:9:3
    9   toHaveClass: (expected: any, ...rest: string[]) => MatcherReturnType
        ~~~~~~~~~~~
    'toHaveClass' was also declared here.

Reproduction:

https://www.typescriptlang.org/play/?ts=5.1.6#code/PTAEHUFMBsGMHsC2lQBd5oBYoCoE8AHSAZVgCcBLA1UABWgEM8BzM+AVwDsATAGiwoBnUENANQAd0gAjQRVSQAUCEmYKsTKGYUAbpGF4OY0BoadYKdJMoL+gzAzIoz3UNEiPOofEVKVqAHSKymAAmkYI7NCuqGqcANag8ABmIjQUXrFOKBJMggBcISGgoAC0oACCbvCwDKgU8JkY7p7ehCTkVDQS2E6gnPCxGcwmZqDSTgzxxWWVoASMFmgYkAAeRJTInN3ymj4d-jSCeNsMq-wuoPaOltigAKoASgAywhK7SbGQZIIz5VWCFzSeCrZagNYbChbHaxUDcCjJZLfSDbExIAgUdxkUBIursJzCFJtXydajBDIKMjJBhLACydQ030ekFQ+M4+1AAG9FCUCAxBAVxvB4C1ODzQMgBQxmJB8qAABQASlAAF4AHxXVCUTjMRQAX3J22+1KWAHk9GRoPAGNxINx6ahGT8ueL0AAJBh6ADCjAFcvlEMgsAU3DlZjw-ACUYJqDlgi1wwA2gBdZXq0AOp3M1lkdntV3wD3e32C+XikqB4N2sOcCPlkwlgByDGQcYTOt49fg1AanEEAH45Zy1jTY0KRR5OHrOyU0xrM71s2z9vqgA

Problem description:

matchers-standalone.d.ts seems to have an invalid syntax. See microsoft/TypeScript#4462 for a longer explanation.

Suggested solution:

interface OverloadedMatchers {
  toHaveClass(expected: any, ...rest: string[]) : MatcherReturnType
  toHaveClass(
    expected: any,
    className: string,
    options?: {exact: boolean},
  ) : MatcherReturnType
}

seems to work, and is probably what the original code intended (overloaded method signature). Note the change from arrow function to class method syntax.

@james-nash
Copy link

Encountered this exact same issue too.

FWIW, I've got @testing-library/jest-dom 6.4.6, which is being installed into my project via @storybook/test 8.1.10. I'm working around it for now by setting skibLibCheck to true in my tsconfig.json, but would prefer not to have to do that.

@gnapse
Copy link
Member

gnapse commented Jul 1, 2024

Suggested solution:

Would you mind opening a PR to introduce that change?

tonyhallett added a commit to tonyhallett/jest-dom that referenced this issue Jul 15, 2024
@tonyhallett
Copy link
Contributor

gnapse #611

@tai2
Copy link

tai2 commented Jul 19, 2024

It was introduced at v6.2.1

  "resolutions": {
    "@testing-library/jest-dom": "6.2.0"
  },

This could work around the issue until it's fixed.

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

5 participants