Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@augustjk
Copy link
Member

@augustjk augustjk commented Sep 1, 2023

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/compat typings that provide their versions of React types.

Due to preactjs/preact#4124, we need to use our own copy of PropsWithoutRef type for proper type checking to occur with preact/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/preact project configured now to use preact/compat. I have also tested this after manually updating the typescript dependency version for the example project.

@changeset-bot
Copy link

changeset-bot bot commented Sep 1, 2023

🦋 Changeset detected

Latest commit: 2e6f5e7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lit-labs/react Patch

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -6% - +9% (-1.05ms - +1.73ms)
    this-change vs tip-of-tree

render

  • this-change: 69.22ms - 73.14ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -3% - +6% (-0.80ms - +1.46ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +0% (-1.18ms - +0.23ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +0% (-1.57ms - +0.02ms)
    this-change vs tip-of-tree

update

  • this-change: 667.09ms - 681.11ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +5% (-2.80ms - +3.25ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -3% - +1% (-2.70ms - +1.08ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -1% - +0% (-7.30ms - +1.86ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 640.68ms - 649.78ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -0% - +1% (-1.94ms - +5.25ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
69.22ms - 73.14ms-

update

VersionAvg timevs
667.09ms - 681.11ms-

update-reflect

VersionAvg timevs
640.68ms - 649.78ms-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
25.93ms - 27.55ms-unsure 🔍
-3% - +6%
-0.80ms - +1.46ms
unsure 🔍
-4% - +4%
-1.20ms - +1.10ms
tip-of-tree
tip-of-tree
25.62ms - 27.19msunsure 🔍
-5% - +3%
-1.46ms - +0.80ms
-unsure 🔍
-6% - +3%
-1.52ms - +0.74ms
previous-release
previous-release
25.98ms - 27.61msunsure 🔍
-4% - +5%
-1.10ms - +1.20ms
unsure 🔍
-3% - +6%
-0.74ms - +1.52ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
68.87ms - 73.20ms-unsure 🔍
-4% - +5%
-2.80ms - +3.25ms
unsure 🔍
-3% - +5%
-1.86ms - +3.66ms
tip-of-tree
tip-of-tree
68.70ms - 72.93msunsure 🔍
-5% - +4%
-3.25ms - +2.80ms
-unsure 🔍
-3% - +5%
-2.04ms - +3.40ms
previous-release
previous-release
68.43ms - 71.85msunsure 🔍
-5% - +3%
-3.66ms - +1.86ms
unsure 🔍
-5% - +3%
-3.40ms - +2.04ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
18.61ms - 20.59ms-unsure 🔍
-6% - +9%
-1.05ms - +1.73ms
unsure 🔍
-6% - +9%
-1.15ms - +1.68ms
tip-of-tree
tip-of-tree
18.28ms - 20.23msunsure 🔍
-9% - +5%
-1.73ms - +1.05ms
-unsure 🔍
-8% - +7%
-1.48ms - +1.32ms
previous-release
previous-release
18.33ms - 20.34msunsure 🔍
-9% - +6%
-1.68ms - +1.15ms
unsure 🔍
-7% - +8%
-1.32ms - +1.48ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
46.83ms - 47.78ms-unsure 🔍
-2% - +0%
-1.18ms - +0.23ms
unsure 🔍
-3% - +0%
-1.44ms - +0.03ms
tip-of-tree
tip-of-tree
47.26ms - 48.30msunsure 🔍
-0% - +3%
-0.23ms - +1.18ms
-unsure 🔍
-2% - +1%
-1.00ms - +0.54ms
previous-release
previous-release
47.44ms - 48.57msunsure 🔍
-0% - +3%
-0.03ms - +1.44ms
unsure 🔍
-1% - +2%
-0.54ms - +1.00ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
98.05ms - 100.24ms-unsure 🔍
-3% - +1%
-2.70ms - +1.08ms
unsure 🔍
-3% - +1%
-2.98ms - +0.84ms
tip-of-tree
tip-of-tree
98.41ms - 101.50msunsure 🔍
-1% - +3%
-1.08ms - +2.70ms
-unsure 🔍
-2% - +2%
-2.47ms - +1.94ms
previous-release
previous-release
98.65ms - 101.79msunsure 🔍
-1% - +3%
-0.84ms - +2.98ms
unsure 🔍
-2% - +2%
-1.94ms - +2.47ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
42.02ms - 43.11ms-unsure 🔍
-4% - +0%
-1.57ms - +0.02ms
unsure 🔍
-2% - +2%
-0.75ms - +0.71ms
tip-of-tree
tip-of-tree
42.75ms - 43.92msunsure 🔍
-0% - +4%
-0.02ms - +1.57ms
-unsure 🔍
-0% - +4%
-0.01ms - +1.52ms
previous-release
previous-release
42.09ms - 43.07msunsure 🔍
-2% - +2%
-0.71ms - +0.75ms
unsure 🔍
-3% - -0%
-1.52ms - +0.01ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
650.19ms - 657.13ms-unsure 🔍
-1% - +0%
-7.30ms - +1.86ms
unsure 🔍
-1% - +1%
-5.02ms - +3.99ms
tip-of-tree
tip-of-tree
653.39ms - 659.37msunsure 🔍
-0% - +1%
-1.86ms - +7.30ms
-unsure 🔍
-0% - +1%
-1.94ms - +6.35ms
previous-release
previous-release
651.30ms - 657.05msunsure 🔍
-1% - +1%
-3.99ms - +5.02ms
unsure 🔍
-1% - +0%
-6.35ms - +1.94ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
661.99ms - 666.83ms-unsure 🔍
-0% - +1%
-1.94ms - +5.25ms
unsure 🔍
-0% - +1%
-2.52ms - +4.36ms
tip-of-tree
tip-of-tree
660.09ms - 665.41msunsure 🔍
-1% - +0%
-5.25ms - +1.94ms
-unsure 🔍
-1% - +0%
-4.35ms - +2.87ms
previous-release
previous-release
661.05ms - 665.93msunsure 🔍
-1% - +0%
-4.36ms - +2.52ms
unsure 🔍
-0% - +1%
-2.87ms - +4.35ms
-

tachometer-reporter-action v2 for Benchmarks

Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz left a 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!

Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Collaborator

@justinfagnani justinfagnani left a 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.

'index',
'create-component',
'use-controller',
'props-without-ref',
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz Sep 5, 2023

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
@augustjk
Copy link
Member Author

augustjk commented Sep 6, 2023

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.

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.

@justinfagnani
Copy link
Collaborator

It's included as rollup config to generate the js and js.map files but it is type only.

Ah. In that case I'd like to use import type to note that it will elide the import completely, and then skip the .js files. But...

Can we just inline the type into create-component.ts? We can still indicate that we copied it from DefinitelyTyped with a link to the file. It's only ~60 chars or so.

@AndrewJakubowicz
Copy link
Contributor

Can we just inline the type into create-component.ts?

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 import type

@justinfagnani
Copy link
Collaborator

Since it's a one-liner, can we just inline something?

Here's a version that's not a copy that distributes Omit:

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 OmitRef<..., 'ref'> even if the original type didn't have ref in it. I don't think this is bad, considering the only place we use the type is in a complex type anyway.

This was tested by updating example/preact to 5.2 and
ensuring it builds correctly with `build:ts`.
@AndrewJakubowicz
Copy link
Contributor

Applied code review feedback. @justinfagnani, I needed to tweak the type slightly more to get the generic distributive omit to type check.

Test plan

I manually tested this change against examples/preact with TypeScript 5.2 and the error no longer occurs.
Requesting re-review from @justinfagnani or @rictic .

Copy link
Collaborator

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@augustjk augustjk mentioned this pull request Sep 26, 2023
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.

[labs/react] Created component type is incompatible in Preact with typescript >=5.1

4 participants