-
Notifications
You must be signed in to change notification settings - Fork 1k
[labs/react] Remove custom children type and include our own copy of PropsWithoutRef for usage with preact/compat
#4172
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: 2e6f5e7 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
|
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.
Fantastic investigating and solution!
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!
justinfagnani
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.
LGTM, with a question on if the new file needs to be in the rollup config entrypoints.
We're not publishing in exports, so it doesn't matter that much, but we are putting the file in the top-level, so someone not using package exports could import this file.
packages/labs/react/rollup.config.js
Outdated
| 'index', | ||
| 'create-component', | ||
| 'use-controller', | ||
| 'props-without-ref', |
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 this be listed as an entrypoint?
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.
+1. We should keep exports and entrypoints in sync.
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.
I reverted entrypoints so it doesn't contain the new file "props-without-ref"
Remove the new file from entrypoint
It's included as rollup config to generate the js and js.map files but it is type only. I wasn't sure if the type import would resolve with just the d.ts file present. It's an empty file so i think it's no harm to have it emit and included in the package without any package export mapping. |
Ah. In that case I'd like to use Can we just inline the type into |
This is my fault since I asked to keep the license with the copied source code. By copying the code & license into a separate file it's easier to delete in the future when the type is included in preact's compatibility types. +1 to |
|
Since it's a one-liner, can we just inline something? Here's a version that's not a copy that distributes type DistributiveOmit<T, K extends string | number | symbol> = T extends any ? Omit<T, K> : T;
// usage
export type OmitRef<T> = DistributiveOmit<T, 'ref'>;The only difference is that in editors if you hover over the type you'll always see the |
This was tested by updating example/preact to 5.2 and ensuring it builds correctly with `build:ts`.
|
Applied code review feedback. @justinfagnani, I needed to tweak the type slightly more to get the generic distributive omit to type check. Test planI manually tested this change against examples/preact with TypeScript 5.2 and the error no longer occurs. |
justinfagnani
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.
thanks!
Fixes #4169, #4138
Instead of trying to figure out React-Preact compatible types ourselves like the franken-child type, it would be better for us to defer to
preact/compattypings that provide their versions of React types.Due to preactjs/preact#4124, we need to use our own copy of
PropsWithoutReftype for proper type checking to occur withpreact/compat.This will also ensure we don't mix React and Preact types for users of TS >= 5.1 where the types become further incompatible.
Tested with our
examples/preactproject configured now to usepreact/compat. I have also tested this after manually updating the typescript dependency version for the example project.