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

TypeScript: unexpected type errors when exactOptionalPropertyTypes is enabled #1320

Open
OliverJAsh opened this issue May 3, 2024 · 0 comments

Comments

@OliverJAsh
Copy link

  • @testing-library/react version: see below
  • Testing Framework and version: N/A
  • DOM Environment:

Relevant code or config:

{
  "dependencies": {
    "@testing-library/react": "^15.0.6",
    "typescript": "^5.4.5"
  }
}
{
  "compilerOptions": {
    "strict": true,
    "exactOptionalPropertyTypes": true,
    "lib": ["DOM", "ESNext"]
  }
}
import { renderHook } from '@testing-library/react';
renderHook;

What happened:

$ yarn run tsc
yarn run v1.22.22
warning package.json: No license field
$ /Users/oliver/Code/reduced-test-cases/testing-library-react-exactOptionalPropertyTypes/node_modules/.bin/tsc
node_modules/@testing-library/react/types/index.d.ts:58:18 - error TS2430: Interface 'ClientRenderOptions<Q, Container, BaseElement>' incorrectly extends interface 'RenderOptions<Q, Container, BaseElement>'.
  Types of property 'hydrate' are incompatible.
    Type 'boolean | undefined' is not assignable to type 'boolean'.
      Type 'undefined' is not assignable to type 'boolean'.

58 export interface ClientRenderOptions<
                    ~~~~~~~~~~~~~~~~~~~

node_modules/@testing-library/react/types/index.d.ts:185:18 - error TS2430: Interface 'ClientRenderHookOptions<Props, Q, Container, BaseElement>' incorrectly extends interface 'RenderHookOptions<Props, Q, Container, BaseElement>'.
  Types of property 'hydrate' are incompatible.
    Type 'boolean | undefined' is not assignable to type 'boolean'.

185 export interface ClientRenderHookOptions<
                     ~~~~~~~~~~~~~~~~~~~~~~~


Found 2 errors in the same file, starting at: node_modules/@testing-library/react/types/index.d.ts:58

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Reproduction:

See above.

Problem description:

Unexpected TypeScript errors regarding exactOptionalPropertyTypes.

Suggested solution:

In ClientRenderHookOptions and ClientRenderOptions (node_modules/@testing-library/react/types/index.d.ts):

-  hydrate?: false | undefined
+  hydrate?: false
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

1 participant