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

Add TypeScript types #60

Closed
wants to merge 2 commits into from
Closed

Add TypeScript types #60

wants to merge 2 commits into from

Conversation

alsiola
Copy link

@alsiola alsiola commented Dec 6, 2018

As discussed in #40 and #59, this PR adds a definitions file (index.d.ts) that provides typings for the library. Due to current TS limitations with respect to variadic types, the syntax is a bit messy. These types will support up to 10 components being passed in in the components prop. Up to 5 arguments are supported when the render function is non-unary. If you are aware that common usage of react-composer would exceed these numbers, then I can certainly make the types support more, but my experience of render-props components is that these are probably high-end for how people are likely to use them.

The index.d.ts file is located in the src file, alongside the index.js for which it defines types. I have added a cp command at the end of the npm build script to move this to an appropriate directory that is included in the npm distribution.

It adds a dev dependency on @types/react - this is only really present to make it easier to work with the definitions in the future should they need improvement/change. It should have no impact on the distributed bundles.

There is example usage of these types in comments at the top of the index.d.ts file. These can copied to test the types work as expected, but also serve as a reference for TypeScript users - when using new typings it is common to view their definitions, and examples are most likely to be seen in this file.

Please let me know if you have any comments or improvements, or if the types don't work correctly in any way.

Alex Young added 2 commits December 6, 2018 00:07
Includes dev dependency on react typings (no impact on compiled
library), and cp command in build process to ensure types are
included in the distributed package.
This is a common place users of the types will look for information
on how they should be used
@jamesplease
Copy link
Owner

jamesplease commented Dec 6, 2018

Thanks for opening this PR, @alsiola !

@dannycochran what do you think of this approach?

@coveralls
Copy link

Pull Request Test Coverage Report for Build 168

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 167: 0.0%
Covered Lines: 7
Relevant Lines: 7

💛 - Coveralls

@jamesplease
Copy link
Owner

I'm getting better at TypeScript, so I might be able to weigh in on this soon 😅 If anyone else has thoughts, do share them!

@jamesplease jamesplease added the help wanted Extra attention is needed label Feb 12, 2019
@orzarchi
Copy link

orzarchi commented Dec 3, 2020

so... any chance for this PR to be merged?

@jamesplease
Copy link
Owner

jamesplease commented Dec 3, 2020

I need to look more into TS 4.0, but it may be possible to write these types in a more succinct (and accurate) way with the new variadic tuples feature, so I'd like to explore that possibility first.

If anyone has time to make a PR (or drop a comment on why variadic tuples wouldn't work here) that'd be the fastest way for there to be progress. Thanks!

@alsiola alsiola closed this Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants