flow
flow copied to clipboard
A safe cast to string makes Flow lose track of types?
// @flow
type Client = {
clientId: string,
redirectUri: string | Array<string>,
};
function f1(client: Client) {}
function f2(clients: {[string]: Client}) {}
const clientSpec = {
clientId: ('hi': string), // Removing this redundant cast makes Flow report the error we want
// missing field 'redirectUri'
}
// GOOD: Flow reports error "property redirectUri is missing"
f1(clientSpec);
// BAD: Flow doesn't report error
f2({[clientSpec.clientId]: clientSpec})
(My actual codebase doesn't have a redundant string cast. But I had trouble constructing a small test case that exhibited the problem; this is the best I could manage.)