Lets say I have a React component that has a \"state\" with 10 fields:
this.state = {
field1: 1,
field2: 2,
... other fields
something: \'a\'
};
You would actually mark all the members of State
as optional.
interface State {
field1?: number,
field2?: number,
}
This is not as unsafe as you might think. TypeScript added the concept of freshness to support this pattern and others.
This is covered here :
https://basarat.gitbooks.io/typescript/content/docs/types/freshness.html#use-case--react-state