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

Breakpoints override fails in .tsx files #20292

Closed
cooperate opened this issue Mar 26, 2020 · 5 comments · Fixed by #20901
Closed

Breakpoints override fails in .tsx files #20292

cooperate opened this issue Mar 26, 2020 · 5 comments · Fixed by #20901

Comments

@cooperate
Copy link

cooperate commented Mar 26, 2020

Overriding breakpoints through createMuiTheme fails in typescript files.

Current Behavior 😯

Typescript throws
Argument of type '"xlg"' is not assignable to parameter of type 'number | "xs" | "sm" | "md" | "lg" | "xl"'.ts(2345)
when breakpoint has been overridden correctly.

Expected Behavior 🤔

Breakpoint should override in makeStyles.

Steps to Reproduce 🕹

createMuiTheme function
createMuiTheme({ breakpoints: { keys: ["xs", "sm", "md", "lg", "xlg", "xl"], values: { xs: 0, sm: 600, md: 960, lg: 1280, xlg: 1872, xl: 1920 } },

use in makeStyles
[theme.breakpoints.down("xlg")]: { content: 'Screen size = xlg' },

xlg throws error in vscode.

Your Environment 🌎

Tech Version
Material-UI v4.9.2
TypeScript v3.6.3
@oliviertassinari
Copy link
Member

You need to augment the theme: https://material-ui.com/guides/typescript/#customization-of-theme.

@oliviertassinari oliviertassinari added the support: Stack Overflow Please ask the community on Stack Overflow label Mar 26, 2020
@support

This comment has been minimized.

@support support bot closed this as completed Mar 26, 2020
@JasonHK
Copy link
Contributor

JasonHK commented May 1, 2020

You need to augment the theme: https://material-ui.com/guides/typescript/#customization-of-theme.

@oliviertassinari Sorry, but module augmentation is not possible since type keyword is not overridable.

declare module "@material-ui/core/styles/createBreakpoints"
{
    export type Breakpoint = "xs" | "sm" | "md" | "lg"; 
}

The above module augmentation will throw the following error:

Duplicate identifier 'Breakpoint'. ts(2300)
createBreakpoints.d.ts(1, 13): 'Breakpoint' was also declared here.

@oliviertassinari
Copy link
Member

I guess that in this case, you could need to augment Breakpoints. Do you have any solution in mind? We recently had a similar concern in #20212.

@JasonHK
Copy link
Contributor

JasonHK commented May 4, 2020

I guess that in this case, you could need to augment Breakpoints. Do you have any solution in mind? We recently had a similar concern in #20212.

@oliviertassinari I've come up a way to fix this in #20901.

@oliviertassinari oliviertassinari added typescript and removed support: Stack Overflow Please ask the community on Stack Overflow labels May 6, 2020
@support support bot reopened this May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants