Skip to content
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

Merged
merged 12 commits into from Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/index.d.ts
Expand Up @@ -48,6 +48,11 @@ type Diff<T extends string, U extends string> = (
/** @internal */
export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;

/** @internal */
export type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>;
}

export namespace PropTypes {
type Alignment = 'inherit' | 'left' | 'center' | 'right' | 'justify';
type Color = 'inherit' | 'primary' | 'accent' | 'default';
Expand Down
3 changes: 2 additions & 1 deletion src/styles/createTypography.d.ts
@@ -1,5 +1,6 @@
import * as React from 'react';
import { Palette } from './createPalette';
import { DeepPartial } from '..'

export type TextStyle =
| 'display1'
Expand Down Expand Up @@ -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<Typography>;

export default function createTypography(
palette: Palette,
Expand Down
6 changes: 6 additions & 0 deletions src/styles/createTypography.spec.js
Expand Up @@ -34,4 +34,10 @@ describe('createTypography', () => {
const typography = createTypography(palette, { htmlFontSize: 10 });
assert.strictEqual(typography.display4.fontSize, '11.2rem');
});

it('should create a typography with custom display4', () => {
const customFontSize = '18px';
const typography = createTypography(palette, { display4: { fontSize: customFontSize } });
assert.strictEqual(typography.display4.fontSize, customFontSize);
});
Copy link
Member

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.

Copy link
Author

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.

});
9 changes: 9 additions & 0 deletions test/typescript/styles.spec.tsx
Expand Up @@ -94,6 +94,15 @@ const customTheme = createMuiTheme({
},
});

const customThemeTypographyPartial = createMuiTheme({
typography: {
display4: {
fontSize: '18px'
},
fontSize: 18
},
});

function OverridesTheme() {
return (
<MuiThemeProvider theme={theme}>
Expand Down