Skip to content

Commit

Permalink
[core] Fix typescript errors related to jss v10
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Dec 28, 2018
1 parent 36f2b60 commit 3b4e229
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 29 deletions.
23 changes: 10 additions & 13 deletions packages/material-ui-styles/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ declare module '@material-ui/styles' {
}

declare module '@material-ui/styles/createGenerateClassName' {
import { GenerateClassName } from 'jss';
import { GenerateId } from 'jss';

export interface GenerateClassNameOptions {
dangerouslyUseGlobalCSS?: boolean;
productionPrefix?: string;
seed?: string;
}

export default function createGenerateClassName(
options?: GenerateClassNameOptions,
): GenerateClassName;
export default function createGenerateClassName(options?: GenerateClassNameOptions): GenerateId;
}

declare module '@material-ui/styles/createStyles' {
Expand Down Expand Up @@ -66,9 +64,9 @@ declare module '@material-ui/styles/install' {
}

declare module '@material-ui/styles/jssPreset' {
import { JSSOptions } from 'jss';
import { JssOptions } from 'jss';

export default function jssPreset(): JSSOptions;
export default function jssPreset(): JssOptions;
}

declare module '@material-ui/styles/makeStyles' {
Expand Down Expand Up @@ -96,7 +94,7 @@ declare module '@material-ui/styles/makeStyles' {

export default function makeStyles<S extends Styles<any, any>>(
styles: S,
options?: WithStylesOptions<ClassKeyOfStyles<S>>,
options?: WithStylesOptions,
): StylesHook<S>;
}

Expand Down Expand Up @@ -128,12 +126,12 @@ declare module '@material-ui/styles/styled' {
}

declare module '@material-ui/styles/StylesProvider' {
import { GenerateClassName, JSS } from 'jss';
import { GenerateId, Jss } from 'jss';

interface StylesOptions {
disableGeneration?: boolean;
generateClassName?: GenerateClassName;
jss?: JSS;
generateClassName?: GenerateId;
jss?: Jss;
// TODO need info @oliviertassinari
sheetsCache?: {};
// TODO need info @oliviertassinari
Expand Down Expand Up @@ -204,8 +202,7 @@ declare module '@material-ui/styles/withStyles' {
| StyleRules<Props, ClassKey>
| StyleRulesCallback<Theme, Props, ClassKey>;

export interface WithStylesOptions<ClassKey extends string = string>
extends JSS.CreateStyleSheetOptions<ClassKey> {
export interface WithStylesOptions extends JSS.StyleSheetFactoryOptions {
flip?: boolean;
withTheme?: boolean;
name?: string;
Expand Down Expand Up @@ -249,7 +246,7 @@ declare module '@material-ui/styles/withStyles' {

export default function withStyles<
S extends Styles<any, any>,
Options extends WithStylesOptions<ClassKeyOfStyles<S>> = {}
Options extends WithStylesOptions = {}
>(
style: S,
options?: Options,
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui-styles/test/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ function testGetThemeProps(theme: Theme, props: AppBarProps): void {
makeStyles(styles, {
flip: true,
name: 'some-sheet',
generateClassName: (_, sheet) => (sheet ? sheet.classes.root : 'no-sheet'),
generateId: (_, sheet) => (sheet ? sheet.classes.root : 'no-sheet'),
});
makeStyles(styles, {
// Property 'toot' does not exist on type 'Record<"root", string>'
generateClassName: (_, sheet) => (sheet ? sheet.classes.toot : 'no-sheet'), // $ExpectError
// rules are added at runtime so no compile time error
generateId: (_, sheet) => (sheet ? sheet.classes.toot : 'no-sheet'),
});

// optional props
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/styles/MuiThemeProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StyleRules, StylesCreator } from './withStyles';

interface SheetManagerTheme {
refs: number;
sheet: StyleSheet<string>;
sheet: StyleSheet;
}

export interface MuiThemeProviderProps {
Expand Down
6 changes: 2 additions & 4 deletions packages/material-ui/src/styles/createGenerateClassName.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { GenerateClassName } from 'jss';
import { GenerateId } from 'jss';

export interface GenerateClassNameOptions {
dangerouslyUseGlobalCSS?: boolean;
productionPrefix?: string;
seed?: string;
}

export default function createGenerateClassName(
options?: GenerateClassNameOptions,
): GenerateClassName;
export default function createGenerateClassName(options?: GenerateClassNameOptions): GenerateId;
4 changes: 2 additions & 2 deletions packages/material-ui/src/styles/jssPreset.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { JSSOptions } from 'jss';
import { JssOptions } from 'jss';

export default function jssPreset(): JSSOptions;
export default function jssPreset(): JssOptions;
8 changes: 2 additions & 6 deletions packages/material-ui/src/styles/withStyles.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export interface StylesCreator {
themingEnabled: boolean;
}

export interface WithStylesOptions<ClassKey extends string = string>
extends JSS.CreateStyleSheetOptions<ClassKey> {
export interface WithStylesOptions extends JSS.StyleSheetFactoryOptions {
flip?: boolean;
withTheme?: boolean;
name?: string;
Expand Down Expand Up @@ -58,10 +57,7 @@ export interface StyledComponentProps<ClassKey extends string = string> {
innerRef?: React.Ref<any> | React.RefObject<any>;
}

export default function withStyles<
ClassKey extends string,
Options extends WithStylesOptions<ClassKey> = {}
>(
export default function withStyles<ClassKey extends string, Options extends WithStylesOptions = {}>(
style: StyleRulesCallback<ClassKey> | StyleRules<ClassKey>,
options?: Options,
): PropInjector<WithStyles<ClassKey, Options['withTheme']>, StyledComponentProps<ClassKey>>;

0 comments on commit 3b4e229

Please sign in to comment.