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 Improvements and Refactoring on CSVReader | style object type refactoring #149

Open
berkinanik opened this issue Feb 24, 2023 · 1 comment · May be fixed by #150
Open

TypeScript Improvements and Refactoring on CSVReader | style object type refactoring #149

berkinanik opened this issue Feb 24, 2023 · 1 comment · May be fixed by #150

Comments

@berkinanik
Copy link

berkinanik commented Feb 24, 2023

I want to mention two issues I faced while using react-papaparse:

  • Poor TypeScript type inference on children render function arguments and prop types for CSVReader component.
  • Too many any type definition, unnecessary CSSProperties type castings and style?: any usages.

I have a fix proposal which includes updating useCSVReader by rewriting many props and type definitions and refactoring all the use cases regarding those updates. Also, updating examples on styling the CSVReader and removing style type castings.

With this properly typed CSVReader component and useCSVReader hook, the component itself and its render children function have proper type inference. Many unnecessary explicit type definitions can be removed. This way typescript support is meaningful since there are no more any type usage in returned component from the useCSVReader hook.

@berkinanik
Copy link
Author

  • Generic element types (HTMLDivElement or HTMLButtonElement) used for root and clickable remove elements which allow getRemoveFileProps and getRootProps to be properly types are added for useCSVReader.
  • Return types are updated for the hook, ProgressBar and Remove components as ComponentType which allows proper prop intellisense while using the components.
  • Event handler functions are generically typed using that generic element type for proper event handler types and event types. No more explicit event type definition is required.
  • ParseResult fn is updated so result is properly typed. Its object attributes can now be viewed using intellisense.

#150 includes further explanation and screenshots of fixed things and shows usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant