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
[theme] Fix TypographyOptions type #9364
Conversation
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.
Can you add the the snippet you used in the PR description to styles.spec.tsx
so as to prevent regressions?
src/styles/createTypography.d.ts
Outdated
@@ -36,7 +36,7 @@ export interface TypographyStyle { | |||
|
|||
export type Typography = { [type in Style]: TypographyStyle } & FontStyle; | |||
|
|||
export type TypographyOptions = Partial<FontStyle> & Partial<Typography>; | |||
export type TypographyOptions = Partial<FontStyle> & Partial<{ [type in Style]: Partial<TypographyStyle> }>; |
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.
This seems a little more straightforward?
type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>;
};
export type TypographyOptions = DeepPartial<Typography>;
const customFontSize = '18px'; | ||
const typography = createTypography(palette, { display4: { fontSize: customFontSize } }); | ||
assert.strictEqual(typography.display4.fontSize, customFontSize); | ||
}); |
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.
This test is fine, but it doesn't really relate to this PR, since it's a runtime (JS) test. What we need is something that checks for compilation failures, see here.
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.
Sorry, misread the name of the file you wanted me to add the test to.
src/styles/createTypography.d.ts
Outdated
export type TypographyOptions = Partial<FontStyle> & Partial<Typography>; | ||
export type DeepPartial<T> = { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
}; |
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.
This should probably go in index.d.ts
along with Diff
and Omit
... we will need it to fix #9333 too.
src/styles/createTypography.d.ts
Outdated
[P in keyof T]?: DeepPartial<T[P]>; | ||
}; | ||
|
||
export type TypographyOptions = Partial<FontStyle> & DeepPartial<TypographyStyle>; |
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.
You didn't actually make use of DeepPartial
yet :)
src/styles/index.d.ts
Outdated
|
||
export type DeepPartial<T> = { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
} |
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.
Sorry, I meant src/index.d.ts
src/styles/createTypography.d.ts
Outdated
@@ -36,7 +37,7 @@ export interface TypographyStyle { | |||
|
|||
export type Typography = { [type in Style]: TypographyStyle } & FontStyle; | |||
|
|||
export type TypographyOptions = Partial<FontStyle> & Partial<Typography>; | |||
export type TypographyOptions = Partial<FontStyle> | DeepPartial<TypographyStyle>; |
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.
Should be just
export type TypographyOptions = DeepPartial<Typography>;
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.
It doesn't work like that
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.
What's the problem?
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.
Trying to reproduce it on the playground. No luck so far. Maybe it's a problem with my local env
src/styles/createTypography.d.ts
Outdated
@@ -1,5 +1,6 @@ | |||
import * as React from 'react'; | |||
import { Palette } from './createPalette'; | |||
import { DeepPartial } from './index' |
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.
import { DeepPartial } from '..'
src/styles/createTypography.d.ts
Outdated
@@ -36,7 +37,7 @@ export interface TypographyStyle { | |||
|
|||
export type Typography = { [type in Style]: TypographyStyle } & FontStyle; | |||
|
|||
export type TypographyOptions = Partial<FontStyle> & Partial<Typography>; | |||
export type TypographyOptions = DeepPartial<TypographyStyle>; |
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.
-export type TypographyOptions = DeepPartial<TypographyStyle>;
+export type TypographyOptions = DeepPartial<Typography>;
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.
Why?
This way you get no mapped type over Style.
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.
But Typography
is already a mapped type over Style
🤔
Thanks for your contribution! |
@pelotom sorry it took me so many comments from you to finally make it. |
…ui#9364) Make TypographyOptions = DeepPartial<Typography>
Without this fix the following code can not be compiled, but it should since we do deep merge anyway