8000 Overhaul types to better describe package functionality by EskiMojo14 · Pull Request #6 · JLarky/react-lazily · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

Overhaul types to better describe package functionality #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

EskiMojo14
Copy link
@EskiMojo14 EskiMojo14 commented Nov 18, 2024

Hi! Big fan of this package, have recommended it a few times and used it in some example apps :)

I wanted to help out and tweak the types to hopefully improve the experience for users.

The changes in this PR:

  • Filters out non-component keys of the module, so they're not suggested
  • Adds an optional peer dependency on the types package for loadable components (@types/loadable__component)
  • Maps components to the correct wrapper types (LazyExoticComponent/LoadableComponent, respectively)
  • Correctly types the parameter passed to lazily's loader as only the keys allows to be accessed (it also adds an assertion in the tests to make sure this is actually passed)

I've bumped to 0.10 as some of the changes here could be potentially breaking to users:

  • Non-component keys now aren't allowed to be accessed (this shouldn't be an issue as the runtime behaviour for this wouldn't have made sense anyway)
  • The wrapper types are written in a way that will likely break generic components. This seems unlikely to be an issue for most to me, but the workaround would just be to cast back to the original type:
const { Select } = lazily(() => import("my-select")) as unknown as typeof import("my-select");

Let me know what you think :)

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.

1 participant
0