Theme: Fix TypeScript 5.9 type error in generate-primitive-tokens script#75748
Theme: Fix TypeScript 5.9 type error in generate-primitive-tokens script#75748
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 6.84 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ciampo
left a comment
There was a problem hiding this comment.
Potentially a better fix would be to widen the type at the iteration level
for ( const [ tokenName, tokenValue ] of Object.entries(
ramp.ramp as Record< string, string >
) ) {But otherwise, the changes are good.
Let's also add a CHANGELOG entry before merging.
03c6c1d to
e11272e
Compare
|
@jeryj I see you enabled auto-merge, but there appears to be a couple failures here. I expect they're flakey tests and should clear up on a restart. Separately, I wonder how come we don't have any feedback to this issue in our existing CI setup? Should we be ensuring these types build clean via Regarding "the theme package's declaration files (index.d.ts etc.) were never emitted", this had me concerned if it was included in the published package (a bigger issue), but they appear to be there (source). I guess the next question would be: Why is it different for For what it's worth, I can't actually verify the original issue. |
|
I cannot reproduce the original issue. We use TypeScript 5.9.3 and there is no type error on the Can you provide more details about what we're actually fixing here? |
|
I think this was something specific to a weird spot in my build. I can't reproduce this either after fully rebuilding my environment. I'll close it out. |
Fixed by Claude
What?
Fixes a TypeScript compilation error in
packages/theme/bin/generate-primitive-tokens/index.tsthat was blocking the fulltsc --buildfrom completing.Why?
TypeScript 5.9 tightened the return type of
Object.entries()for objects whose key type is a union of string literals rather thanstring.ramp.rampis typed asRecord<keyof Ramp, string>— sincekeyof Rampis a union of specific literals, TypeScript no longer matches the typedObject.entries<T>(o: { [s: string]: T })overload. It falls back to the untyped overload, which in TS 5.9 resolves to[string, unknown][]instead of the previous[string, any][]. This madetokenValueunknown, which is not assignable to thestringparameter oftransformColorStringToDTCGValue.The
as stringassertion is safe becauseRecord<keyof Ramp, string>guarantees all values are strings.How?
Adds a
tokenValue as stringtype assertion at the call site. No runtime behavior changes.The compilation failure was also causing downstream "Cannot find module '@wordpress/theme'" errors in
packages/ui,packages/boot, andstorybook/decoratorsbecause the theme package's declaration files (index.d.tsetc.) were never emitted.Testing Instructions
On trunk — shows the failure:
On this branch — shows the fix:
Testing Instructions for Keyboard
Screenshots or screencast