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

Feature - add typescript declarations #16

Merged
merged 4 commits into from
May 18, 2020
Merged

Conversation

dpnolte
Copy link
Contributor

@dpnolte dpnolte commented May 5, 2020

Hi,

Thanks for this awesome library.

With this PR, I'd like to add typings to the package.

There were a couple of issues with typing withESI:

  • Return type - With declarations enabled, typescript generated an error: the esi property cannot be private/protected in the HOC class. That is, exported anonymous classes can't have private or protected members if declaration emit is enabled, because there's no way to represent that in a .d.ts file. I resolved it by providing an return type to withESI React.ComponentClass<P & IWithESIProps>
  • propTypes - The problem with this return type is that the static propTypes member did not account for child properties as provided by the generic variable P. This generated another typescript error. I resolved it by converting the propTypes member first to unknown and then to the proper WeakValidationMap type to account for HOC props and the children props.

@dunglas dunglas merged commit 15170f0 into dunglas:master May 18, 2020
@dunglas
Copy link
Owner

dunglas commented May 18, 2020

Awesome! Thanks @dpnolte

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

Successfully merging this pull request may close these issues.

None yet

2 participants