flow icon indicating copy to clipboard operation
flow copied to clipboard

A safe cast to string makes Flow lose track of types?

Open cakoose opened this issue 5 years ago • 0 comments

// @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})

flow.org/try

(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.)

cakoose avatar Oct 05 '19 02:10 cakoose