{{ message }}
[material-ui][Typography] Enforce type checking for responsive typography shorthand in the sx prop - #49055
Open
Fenomen-Alex wants to merge 8 commits into
Open
Conversation
…aphy shorthand in the sx prop
Author
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
Author
|
Hi! The |
Author
Author
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Closes #42918.
Summary
The
typographyshorthand in thesxprop is typed asstring, which leaves responsive usage ({ xs: ..., sm: ... }) unchecked against the theme typography variants. This tightens the type for theTypographycomponent so invalid responsive variants are caught at compile time.Changes
packages/mui-material/src/Typography/Typography.d.tsTypographySxPropstype:```ts
export type TypographySxProps = SxProps & {
typography?: string | Partial<Record<Breakpoint, TypographyProps[variant]>> | undefined;
};
```
TypographyOwnProps.sxnow usesTypographySxProps. Custom variants remain supported via thestringfallback.AlertTitle,DialogContentText,DialogTitle,Link— updated thesxprop type fromSxProps<Theme>toTypographySxPropssince they extendTypographyand their previous declaration was incompatible with the narrowed type.packages/mui-material/src/Typography/typography.spec.tsx— added type tests for valid scalar/responsive/array/function usage plus an@ts-expect-errorfor an invalid variant key.Verification
Note
As discussed in #42918, the type is applied to the
Typographycomponent first as a starting point; extending it to other components could be a follow-up.