Skip to content

Unable to resolve types reexported from react-onclickoutside #4974

Closed as not planned
@jcrang

Description

@jcrang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions