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.

[react-jss] Version 10.0.3 contains breaking change in Typescript definitions

See original GitHub issue

Expected behavior: In version 10.0.0 and above, the TS definition clearly states that, if user wants to use theme in the function, Theme type must be supplied to the generic createUseStyles type as follows:

declare function createUseStyles<T, C extends string>(
  styles: (theme: T) => Record<C, Style | string>,
  options?: {
    index?: number
    name?: string
    theming?: Theming<T>
  } & StyleSheetFactoryOptions
): (data?: any) => Record<C, string>

Thus user could use types styles with provided theme as follows:

const useStyles = createUseStyles<Theme, "checkboxWrapper" | "input">((theme: Theme) => ({
	checkboxWrapper: {
		display: "inline-flex",
		alignItems: "center",
		fontSize: theme.utils.pxToRem(14),
	},
	input: {
		marginRight: theme.utils.pxToRem(6),
	}
}));

And the useStyles hook would return proper classNames.

Describe the bug: In react-jss@10.0.3 a new typescript definitions were introduced which are breaking against previous behavior. The Theme argument no longer needs to be supplied to the generic which means that every usage of createUseStyles is now broken.

declare function createUseStyles<C extends string = string>(
  styles: ((theme: any) => Styles<C>),
  options?: CreateUseStylesOptions
): (data?: unknown) => Classes<C>

Recommended fix Revert this behavior under 10.0.4 version and release a new major version with this breaking change, according to the semver.

Codesandbox link: Please create a codesandbox.io with the issue. Make it as minimal as possible as this will help us find the bug quicker.

Versions (please complete the following information):

  • react-jss: 10.0.3
  • Browser [e.g. chrome, safari]: yes
  • OS [e.g. Windows, macOS]: yes Feel free to add any additional versions which you may think are relevant to the bug.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:35 (28 by maintainers)

github_iconTop GitHub Comments

2reactions
vtereshyncommented, Jan 29, 2020

So, after upgrading to 10.0.4 I don’t see if issue with types has been fixed:

const styles = {
  verticalDoubleContainer: {
    width: '100%',
    position: 'relative',

    '& .recharts-cartesian-axis-ticks text tspan': {
      textTransform: 'uppercase',
      fill: '#6a7175',
      fontSize: '1rem',
      letterSpacing: '1px'
    }
  }
};

type Props = WithStylesProps<typeof styles> &  {}

And I receive:

 Argument of type '{ verticalDoubleContainer: { width: string; position: string; '& .recharts-cartesian-axis-ticks text tspan': { textTransform: string; fill: string; fontSize: string; letterSpacing: string; }; }; barLabel: { ...; }; barTitle: { ...; }; }' is not assignable to parameter of type 'Record<string | number | symbol, string | JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<void>>>>>>>> | ((theme: any) => Record<...>)'.
  Type '{ verticalDoubleContainer: { width: string; position: string; '& .recharts-cartesian-axis-ticks text tspan': { textTransform: string; fill: string; fontSize: string; letterSpacing: string; }; }; barLabel: { ...; }; barTitle: { ...; }; }' is not assignable to type 'Record<string | number | symbol, string | JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<void>>>>>>>>'.
    Property 'verticalDoubleContainer' is incompatible with index signature.
      Type '{ width: string; position: string; '& .recharts-cartesian-axis-ticks text tspan': { textTransform: string; fill: string; fontSize: string; letterSpacing: string; }; }' is not assignable to type 'string | JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<void>>>>>>>'.
        Type '{ width: string; position: string; '& .recharts-cartesian-axis-ticks text tspan': { textTransform: string; fill: string; fontSize: string; letterSpacing: string; }; }' is not assignable to type 'JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<JssStyleP<void>>>>>>>'.
          Type '{ width: string; position: string; '& .recharts-cartesian-axis-ticks text tspan': { textTransform: string; fill: string; fontSize: string; letterSpacing: string; }; }' is not assignable to type 'CssProperties'.
            Types of property 'position' are incompatible.
              Type 'string' is not assignable to type 'FnValue<"relative" | "-moz-initial" | "inherit" | "initial" | "revert" | "unset" | "fixed" | "-webkit-sticky" | "absolute" | "static" | "sticky" | undefined>'.

136 export default withStyles(styles)(ResponsiveBar);
2reactions
filosgangacommented, Jan 20, 2020

Is there any workaround to make Typescript happy (apart from use the version 10.0.2)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading to React 18 with TypeScript - LogRocket Blog
The upgrade of the React type definitions to support React 18 involved some significant breaking changes that developers should know about.
Read more >
Bug: React 18 types broken since the type release a ... - GitHub
It's not strictly related to React 18 per se, but it's a breaking change the maintainers of React typings have meant to do...
Read more >
React sur Twitter : "The React 18 TypeScript typings are out ...
While any breaking changes to types are unfortunate, the point of using TypeScript is to catch more errors before they get to production....
Read more >
Changelog - Cypress Documentation
This feature is being released as an Alpha, meaning there may be breaking changes in future Cypress releases. Addresses #23037.
Read more >
@types/react - npm
This package contains type definitions for React (http://facebook.github.io/react/). Details. Files were exported from https://github.com/ ...
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