Skip to content

Wrong TS type infered for object created using createUseStyles #1479

@MaximeCheramy

Description

@MaximeCheramy

Expected behavior:

Given the following snippet:

const useStyles = createUseStyles((theme) => ({
  SectionTitle: {
    color: theme.color, // Commenting out this line fixes the bug

    // Bullet
    "&:before": {
      content: (props: JssProps) => `"${props.number}"`,
      border: [1, "solid", "black"]
    }
  }
}));

The type should be:

const useStyles: (data?: JssProps & {
    theme?: Jss.Theme;
}) => Record<"SectionTitle", string>

But instead, it's:

const useStyles: (data?: {
    theme?: Jss.Theme;
}) => Record<"SectionTitle", string>

Describe the bug:

This only occurs in a very specific case:

  • We use the theme in the JSS
  • The Theme is not correctly defined (any)

My theme is actually generated by a webpack plugin, that's why the type not precise.

Reproduction:

https://codesandbox.io/s/bug-type-jss-j5gkw

Versions (please complete the following information):

  • jss: 10.6.0
  • Browser [e.g. chrome, safari]: Chrome / FireFox
  • OS [e.g. Windows, macOS]: Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions