cssinjs/jss

React-jss doesn't ignores defaultProps in Typescript

Open

#1106 aperta il 15 mag 2019

Vedi su GitHub
 (3 commenti) (4 reazioni) (0 assegnatari)JavaScript (434 fork)batch import
help wantedtypescript

Metriche repository

Star
 (7000 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Expected behavior: Typescript 3.0 added support for defaultProps in React.
Using WithStyles seems to break this behavior.

Describe the bug: Props are reported as required even though they are defaulted using a public static defaultProps field.

Codesandbox link: The following code should do it but I can't make it work in CodeSandbox. For some reason, it keeps marking React as any which can't trigger the error.
Here is the url anyway: https://codesandbox.io/s/fk93m

import * as React from "react";
import { render } from "react-dom";
import injectSheet, { WithStyles } from "react-jss";

const styles = {
  blue: {
    color: "blue"
  }
};

interface IProps extends WithStyles<typeof styles> {
  count: number;
}

class App extends React.Component<IProps> {
  public static defaultProps = {
    //count: 18 // Enabling this line triggers a type error when Using RealApp below
  };

  public render() {
    const { classes, count } = this.props;

    return <div className={classes.blue}>The count is {count}.</div>;
  }
}

const RealApp = injectSheet(styles)(App);

render(<RealApp />, document.getElementById("root"));

Versions (please complete the following information):

  • react-jss: ^10.0.0-alpha.16.
  • Browser: Chrome but error is due to typings.
  • OS: Windows
  • Typescript: 3.4.3

Guida contributor