/* @flow */
interface X {
a?: string
};
type Y = {
a?: string
};
const y : Y = {
a: 'arst'
};
// Errors out here
(y : X);
Error:
14: (y : X);
^ Cannot cast `y` to `X` because undefined [1] is incompatible with string [2] in property `a`.
References:
6: a?: string ^ [1]
3: a?: string ^ [2]
There are no errors when a is made not optional (link).
It might have something to do with the variance of the property since setting a to write-only works, though read-only doesn't work (which I imagine is more important for most users).
This makes optional properties inside interfaces essentially unusable.
Bumping this back up, in case it got forgotten.
Most helpful comment
This makes optional properties inside interfaces essentially unusable.