question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript fontWeight too restrictive

See original GitHub issue

Current the typing for fontWeight (used with createStyles) doesn’t allow other weights like “black” or “extra-bold”.

Current typing:

StandardLonghandProperties<TLength = string | 0>.fontWeight?: number | "bolder" | "-moz-initial" | "inherit" | "initial" | "revert" | "unset" | "normal" | "bold" | "lighter" | undefined

Recommended: Make the weight a general string instead of an enum.

Example:

const styles = createStyles({
  root: {
    flexGrow: 1,
  },
  flex: {
    flexGrow: 1,
    fontFamily: 'Montserrat!important',
    fontWeight: 'black'
  }
});

The above code causes the TS error:

[ts] Argument of type ‘{ root: { flexGrow: number; }; flex: { flexGrow: number; fontFamily: string; fontWeight: “black”; }; menuButton: { marginLeft: number; marginRight: number; }; }’ is not assignable to parameter of type ‘Record<“root” | “flex” | “menuButton”, CSSProperties>’. Types of property ‘flex’ are incompatible. Type ‘{ flexGrow: number; fontFamily: string; fontWeight: “black”; }’ is not assignable to type ‘CSSProperties’. Types of property ‘fontWeight’ are incompatible. Type ‘“black”’ is not assignable to type 'number | “-moz-initial” | “inherit” | “initial” | “revert” | “unset” | “normal” | “bold” | “bolder” | “lighter” | undefined

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
Tony-Esalescommented, Jan 14, 2020

How about fontWeight: “bold !important”? It’s necessary use the !important sometimes…

0reactions
oliviertassinaricommented, Mar 22, 2021

@MichaelTrilford-Airwallex We should be good in v5 now with

import { experimentalStyled as styled } from '@material-ui/core/styles';

e.g. open this demo in codesandbox https://next--material-ui.netlify.app/components/checkboxes/#customized-checkbox

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript fontWeight too restrictive · Issue #12628 - GitHub
Current the typing for fontWeight (used with createStyles) doesn't allow other weights like "black" or "extra-bold".
Read more >
Typescript error during inline fontWeight style in React
Specifies font weight. The values 'normal' and 'bold' are supported for most fonts.
Read more >
Any way to strengthen font weight/darkness/heaviness? - TeX
Computer Modern's Typewriter font is much heavier than Courier though, so I find it odd that you're explicitly choosing to use the latter....
Read more >
Inaccurate Preview and Changes to Font Weight
The real problem here is WP restricting the changes that can be made to header fonts by controlling what weights are and aren't...
Read more >
The reasons I don't use Typescript - DEV Community 👩‍💻👨‍💻
I don't remember the details - conditional, discriminate, idk - but the code at runtime was too strict. Custom types made it so....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found