palantir / tslint-react

:orange_book: Lint rules related to React & JSX for TSLint.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

inomdzhon opened this issue · comments

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?

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