react-modal icon indicating copy to clipboard operation
react-modal copied to clipboard

Refactor react-modal to use TypeScript

Open doeg opened this issue 1 year ago • 1 comments

I wanted to open a ticket to discuss the possibility of refactoring this library to use TypeScript. 😸

In addition to all of the benefits typed code has with respect to safety, productivity, and maintainability, built-in types would also remove the need for third-party type definitions. (See https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-modal.)

If we adopt this proposal, we could (and arguably should) do this as a progressive enhancement to the library. Some related guides on adding TypeScript to existing projects:

  • https://github.com/Microsoft/TypeScript-React-Conversion-Guide#typescript-react-conversion-guide
  • https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html

This dovetails with https://github.com/reactjs/react-modal/issues/1036, which proposes a new build system to replace bespoke webpack. If the plan is indeed to move away from webpack, starting with #1036 and then integrating TypeScript after would be the most reasonable sequence of events, I think. :)

https://github.com/reactjs/react-modal/issues/960 is a related issue that flags a type error ('ReactModal' cannot be used as a JSX component) arising from using react-modal with React 18.

@diasbruno would love to know your thoughts on this. 🙇 I did not see any previous discussions around adopting TypeScript in the issues/pull requests for this repo.

doeg avatar Feb 09 '24 18:02 doeg

I think that's fine. We just need to deprecate the ones defined on DefinatelyTyped.

I believe this can be done in 2 steps:

  • [ ] Move to a build system with typescript enabled
  • [ ] Provide the types, or, type the library

diasbruno avatar Feb 10 '24 00:02 diasbruno