-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(theme): keep flat font properties in a mixed configureFonts config #5066
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
Open
giaBaoJS
wants to merge
1
commit into
callstack:main
Choose a base branch
from
giaBaoJS:fix/configure-fonts-mixed-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−20
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
wdyt about supporting custom variants here too?
custom variants are documented, but
{ fontFamily, customVariant: {...} }still produces TS error because this overload only acceptsTypescaleKeymaybe we can use a generic mapped overload that treats
TypescaleStylekeys as shared properties & other object keys as variants?it might look smth like that:
btw, this could be handled separately in follow-up PR
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.
Agreed, and I would rather keep this PR at its current size given it is already approved. I will open the follow-up once this lands.
Two things I checked in the meantime.
The gap is types-only.
configureFontsConfigalready builds custom variants at runtime:variantNamesunionsObject.keys(typescale)withObject.keys(variantOverrides)(src/theme/fonts.tsx:35-38), so{ fontFamily, customVariant: {...} }produces the correct object today and it is only the overloads that reject it. Confirmed the error you describe:TS2769: No overload matches this call. The last overload gave the following error. Type 'string' is not assignable to type 'TypescaleStyle'.Your sketch works. I prototyped it locally:
Tinfers throughMixedFontsConfig<T>,configureFonts({ config: { fontFamily, customVariant: {...} } }).customVariant.fontSizecomes back asnumber, and the existing call shapes ({ fontFamily }alone,{ fontFamily, bodyLarge }, and no argument) all still compile.The one thing I want to settle in the follow-up is overload ordering. Placed first, the generic also claims the plain and mixed built-in cases, so their return type becomes
Typescale & CustomFontVariants<T>instead of plainTypescale. That is structurally the same thing, but I would rather have a test per config shape before changing which overload wins.