jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.71k stars 2.77k forks source link

Typescript compilation error with formik 2.4.5 #3888

Open rcocks-hl opened 9 months ago

rcocks-hl commented 9 months ago

Bug report

Current Behavior

When compiling with a reference to formik 2.4.5 I get the following error:

node_modules/formik/dist/connect.d.ts:2:8 - error TS1259: Module '"<project>/node_modules/@types/hoist-non-react-statics/index"' can only be default-imported using the 'esModuleInterop' flag

2 import hoistNonReactStatics from 'hoist-non-react-statics';
         ~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/hoist-non-react-statics/index.d.ts:80:1
    80 export = hoistNonReactStatics;
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

Expected behavior

Expect to compile without error.

Suggested solution(s)

On line https://github.com/jaredpalmer/formik/blob/0f960aaeeb0bdbef8312b5107cd3374884a0e62b/packages/formik/src/connect.tsx#L2C2-L2C2 replace import hoistNonReactStatics from 'hoist-non-react-statics'; with import * as hoistNonReactStatics from 'hoist-non-react-statics';

Additional context

A mitigation is to have "skipLibCheck": true in compilerOptions of a project tsConfig.

Your environment

Software Version(s)
Formik 2.4.5
React 17.0.2
TypeScript 5.2.2
Browser n/a
npm/Yarn 8.5.5
Operating System windows 11
rcocks-hl commented 9 months ago

What's odd here is that the formik project has "esModuleInterop":true set, so this won't be an error when compiling just formik, but somehow is tripping an error when compiling a project with "esModuleInterop":false that just references formik.