Closed
Description
Traditionally in TS, the absence of value or an explicit undefined value was exactly the same thing.
Perhaps it still even makes sense for Partial, but I thought Partial was meant to solve the React setState problem; and I believe it's still not solved today.
TypeScript Version: 2.1.4
Code
type State = { veryImportant: number }
// This compiles fine with all the mandatory flags (strictNullChecks, etc)
// if setState uses Partial<State>
// This is a huge invariant violation and can happen very easily for instance
// by setting `veryImportant` to a nullable variable.
this.setState({ veryImportant: undefined })
Expected behavior:
A non nullable property should not be updatable with null/undefined with strictNullChecks.
We need to be able to say "give me an object that
- Either do not declare a property I have
- Or if it does, must have the same exact type (not nullable)
By the way, I don't even use React, but this is a fairly common and useful behavior to have.