npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shuhei/typed-recompose

v0.0.1

Published

It's hard to keep prop types of underlying components of HOCs. Even [the official documentation](https://flowtype.org/docs/react.html#higher-order-components) is not working well. It's even harder to have multiple HOCs typed and maintain with peer develop

Downloads

2

Readme

WIP: Typing HOCs with recompose

It's hard to keep prop types of underlying components of HOCs. Even the official documentation is not working well. It's even harder to have multiple HOCs typed and maintain with peer developers. Here comes recompose, the HOC utility module. If we have recompose properly typed, we can omit typing of our own HOCs taking advantage of recompose and flowtype's type inference.

recompose still doesn't have official flowtype definition, but there are some efforts:

  • https://github.com/acdlite/recompose/pull/241
  • https://github.com/flowtype/flow-typed/pull/624

This gist is an effort to make it happen based on the PRs above.

Goals

  • Keep types of underlying component's props
  • Allow underlying component to ignore additional props by HOC
  • No additional type annotations on top of recompose

Implementation details

  • In a union type, a specific type should come before more general types.
    • NG: T | Fn1<A, B>
    • OK: Fn1<A, B> | T
  • HOCs that provide additional props may return HOC<$Shape<A & B>, B>. In this way, the underlying component can ignore some unnecessary intermediate props.
    • For example:
      const withOpen = withValue(false, (open, setOpen) => ({ open, setOpen }));
      const withToggle = withProps(({ open, setOpen }) => ({ toggle: () => setOpen(!open) }));
      
      // `Something` doesn't need `setOpen`!
      function Something({ open, toggle }) { /* ... */ }
      const enhancedSomething = compose(withOpen, withToggle)(Something);
  • suppress_comment suppresses also next next line in addition to next line. So put a new line after the suppression target line.
    • For example:

      // .flowconfig
      [options]
      suppress_comment=^ $ExpectError$
      // or
      suppress_comment=\\(.\\|\n\\)*\\$ExpectError
      // $ExpectError
      'foo'.bar();
      'foo'.bar(); // This line's error is also suppressed!
          
      // $ExpectError
      'foo'.bar();
      
      'foo'.bar(); // This line's error is not suppressed!

Reference