-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Components utils: use Object.assign
instead of { ...spread }
syntax
#39932
Conversation
…o avoid errors in the code generated by TypeScript
Size Change: +77 B (0%) Total Size: 1.22 MB
ℹ️ View Unchanged
|
- Update `BorderControl` and `BorderBoxControl` to allow the passing of custom class names to popovers ([#39753](https://github.com/WordPress/gutenberg/pull/39753)). | ||
|
||
### Internal | ||
|
||
- `BaseControl`: Convert to TypeScript ([#39468](https://github.com/WordPress/gutenberg/pull/39468)). | ||
|
||
### New Features | ||
|
||
- Add `BorderControl` component ([#37769](https://github.com/WordPress/gutenberg/pull/37769)). | ||
- Add `BorderBoxControl` component ([#38876](https://github.com/WordPress/gutenberg/pull/38876)). | ||
- Add `BorderControl` component ([#37769](https://github.com/WordPress/gutenberg/pull/37769)). | ||
- Add `BorderBoxControl` component ([#38876](https://github.com/WordPress/gutenberg/pull/38876)). | ||
|
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.
Changes on these lines are only about aligning the white spacing at the beginning of every list item
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 Marco, this resolves the issue.
I'm wondering though why this happens. Is there a reference you can share to read more about it?
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.
Really interesting 🤔 After reading up on it, I do see how the internal implementation could be different between spreads and assigns. I can't seem to get a minimal repro so I wonder if there's something else involved too. But that's just for curiosity.
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
I also personally don't really know why this was happening — it definitely looks it's a TypeScript bug, but I also found it difficult to reproduce it in isolation. Somehow when using the spread syntax in the affected, TypeScript doesn't seem to be able to fully "expand" the object that is being spread. In the case of I also found some differences between |
I wonder if this is something an option in |
That is also a possibility, although I haven't had the time to look into it after finding a fix. I'll put it in my list of tasks, but anyone feel free to also explore it! |
What?
The changes in this PR refactor the code in the
utils
folder of the@wordpress/components
package, switching toObject.assign()
instead of using the{ ...spread }
syntax.Why?
While working on #39436, I discovered the following issue, which can be replicated by running
npm run build:packages
and inspecting the following generated files:packages/components/build-types/utils/config-values.d.ts
: this file actually contains a couple of circular dependency errors:See screenshot
packages/components/build-types/utils/colors-values.d.ts
: in this file, we can observe that effectively the type of theCOLORS
object doesn't include thewhite
key.How?
In both cases, I was able to solve the issue by using
Object.assign
instead of the{ ...spread }
syntax.Testing Instructions
On trunk:
npm run distclean && npm ci && npm run build:packages
packages/components/build-types/utils/config-values.d.ts
and notice the TypeScript errors.packages/components/build-types/utils/colors-values.d.ts
, and notice how the type of theCOLORS
object doesn't include thewhite
key.Apply the changes from this PR:
npm run distclean && npm ci && npm run build:packages
packages/components/build-types/utils/config-values.d.ts
, there shouldn't be any TypeScript errorspackages/components/build-types/utils/colors-values.d.ts
, the type of theCOLORS
object should include thewhite
key.