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

Unnecessary member-variable-declaration expected for 'state' and 'defaultProps' #174

Closed
inomdzhon opened this issue Jul 27, 2018 · 1 comment

Comments

@inomdzhon
Copy link

Example

export default class ScrollWrapper extends React.Component<PropsType, StateType> {
  static defaultProps = { // <-  TSLint: member-variable-declaration expected: 'defaultProps' to have a typedef (typedef)
    width: 400,
    height: 400,
  };
  state = { // <- TSLint: member-variable-declaration:  'state' to have a typedef (typedef)
    init: false,
  };

  componentDidMount(): void { ... }

  render(): React.ReactElement<'div'> { ... }
}

I think it's wrong validating, because we already put typing inReact.Component<PropsType, StateType> and it's work

type StateType = {
  init: boolean;
};

export default class ScrollWrapper extends React.Component<PropsType, StateType> {
  state = { // <- Error:(25, 3) TS2416: Type 'string' is not assignable to type 'boolean'.
    init: '',
  };
}

Furthermore, there will soon be an update https://blogs.msdn.microsoft.com/typescript/2018/07/12/announcing-typescript-3-0-rc/#default-props-support

Can we fix this?

@adidahiya
Copy link
Contributor

This looks like an instance of the more general problem here: palantir/tslint#711

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants