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

Unable to resolve types reexported from react-onclickoutside #4974

Open
jcrang opened this issue Jul 16, 2024 · 3 comments
Open

Unable to resolve types reexported from react-onclickoutside #4974

jcrang opened this issue Jul 16, 2024 · 3 comments

Comments

@jcrang
Copy link

jcrang commented Jul 16, 2024

Describe the bug

Types reexported from react-onclickoutside cannot be used unless @types/react-onclickoutside is installed as well as react-datepicker.

This means that excludeScrollbar is not correctly typed as a boolean, and TypeScript does not cleanly compile unless the skipLibCheck compiler option is true.

TypeScript fails with:

  node_modules/react-datepicker/dist/index.d.ts(2,60): error TS7016: Could not find a declaration file for module 'react-onclickoutside'. '/repo/UI/Website/node_modules/react-onclickoutside/dist/react-onclickoutside.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/react-onclickoutside` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-onclickoutside';`

To Reproduce

See CodeSandbox; direct link to index.d.ts.

Expected behavior

  • excludeScrollbar is a boolean
  • TypeScript can compile cleanly

Screenshots

image

image

Desktop (please complete the following information):

N/A

Smartphone (please complete the following information):

N/A

Additional context

I think the simplest fix here is to add @types/react-onclickoutside as a dependency rather than dev dependency.

An alternative fix is to redefine the types from @types/react-onclickoutside inline without importing them from react-onclickoutside.

Two workarounds are:

  • Enable the skipLibCheck TypeScript compiler options – this allows TypeScript to compile but does not correct the type of excludeScrollbar.
  • Run npm install --save-dev @types/react-onclickoutside to include the missing types.
@hamidrezahanafi
Copy link
Contributor

Hopefully soon that prop is going to be removed
#4979

@artygrand
Copy link

I don't know, it's related or no, but I got that error on build with new one below

node_modules/react-datepicker/dist/calendar.d.ts:10:26 - error TS2307: Cannot find module 'date-fns/types' or its corresponding type declarations.

10 import type { Day } from "date-fns/types";

@JurajKavka
Copy link

I can't build my UI lib that depends on [email protected] due to missing @types/react-onlclickoutside. Version 7.3.0 depends on react-onlickoutside itself in package.json. In main branch in package.json that dependency is missing so probably with new version it will be 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

4 participants