piotrwitek / react-redux-typescript-guide

The complete guide to static typing in "React & Redux" apps using TypeScript
https://piotrwitek.github.io/react-redux-typescript-guide/
MIT License
13.35k stars 1.09k forks source link

State type inferrence #174

Open shaun-sweet opened 5 years ago

shaun-sweet commented 5 years ago

Currently the guide has for react components the state type defined up with the props. Instead, I propose its changed to be flipped a bit. For example ->

type ownProps = {}
const initialState = {
  isOpen: false
}

class Modal extends React.Component<ownProps, typeof initialState> {
  state = initialState

this better follows the repositories philosophy of implementation being the source of truth

piotrwitek commented 5 years ago

Sounds good, could be added as an alternative approach to the guide in the Class components section.

shaun-sweet commented 5 years ago

cool, i'll submit a PR

piotrwitek commented 5 years ago

@shaun-sweet sure go for it. Please try to keep as much consistency as possible in terms of guide structure and naming/casing conventions across the examples.