flow-try link:
snippet:
type Identifiable<T> = {
id: T,
};
function convertIdentifier2(x: Identifiable<number>): Identifiable<string> {
// this should succeed since we override id to be of string type, but generates type errors
return { ...x, id: x.id.toString() };
}
8: return { ...x, id: x.id.toString() };
^ Cannot return object literal because number [1] is incompatible with string [2] in property `id`.
References:
7: function convertIdentifier2(x: Identifiable<number>): Identifiable<string> {
^ [1]
7: function convertIdentifier2(x: Identifiable<number>): Identifiable<string> {
^ [2]
Here's another example. We basically take one object and transform it into another object, changing a few properties along the way. We have a property that is the same key on both objects, but different types. The spread operator should override the first property and replace it with the second, but flow doesn't detect this.
This no longer errors in master