-
Notifications
You must be signed in to change notification settings - Fork 1k
[labs/react] Loosen type for react module in option #4143
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
Conversation
🦋 Changeset detectedLatest commit: c24e08d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultsthis-change
render
update
update-reflect
this-change, tip-of-tree, previous-release
render
update
nop-update
this-change, tip-of-tree, previous-release
render
update
this-change, tip-of-tree, previous-release
render
update
update-reflect
|
| // Interface that includes parts of the React module that we use. This allows | ||
| // users to construct an object with just the needed methods and prevents type | ||
| // incompatibilities when there are multiple React types being used. | ||
| interface ReactLike { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we export this? I could see someone using this with satisfies to make an object to pass to several createComponent calls. If so, make the comment a doc comment.
75d668a to
c24e08d
Compare
AndrewJakubowicz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
| * createElement, | ||
| * } satisfies ReactLike; | ||
| * | ||
| * createComponnt({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createComponnt -> createComponent
| '@lit-labs/react': patch | ||
| --- | ||
|
|
||
| Make option type for the React module we accept to be looser. This lets users provide a smaller object with just the needed API and mitigate type incompatibilities when multiple copies of React types are present. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for first sentence, I think I prefer the PR title way of specifying what type is loosened.
"Loosen createComponent's options.react type so it only includes the parts of the React API that are used.", or alternatively to be looser -> looser.
|
Upon further exploration and thought, I'm less convinced that this is a valuable change to the package. My main motivation for this was to allow multiple copies of React to type check for the case of our examples directory having a different version of React from the rest of the monorepo but that's actually a valid error as React breaks when multiple copies are used. The only value, then, would be that users can provide a subset of the React module, but that also shoehorns us into only using those API and anything additional would be a breaking change. |
While working making the top level examples directory to part of the npm workspaces here #4111, I noticed the code that wraps the custom element with
createComponent()was failing type check as theReacttype imported in the nextjs example project was a different copy than the one used by@lit-labs/react, and due to things like unique symbol type and function overloading, copies are not compatible. In that PR, I solved the issue by de-duping the@types/reactpackage in the monorepo but we may eventually have valid reasons to have multiple copies of@types/reactin the monorepo (should we add projects/tests with React 17, for instance).The type change done here allows for the nextjs example project and
@lit-labs/reactto have different React types, and also only specifies APIs we use from React so users could create their own bag of React functions rather than passing in the whole module.