Reputation: 7524
Consider:
/* @flow */
export default {test: true};
How best to flowtype this?
The only way I've found is:
/* @flow */
const data : {test: boolean} = {test: true};
export default data;
Is there not a way to do this inline without the const definition?
Background: While flow could infer the definitiion of the object, in my case it's a 200kb large object containing a dataset that is written to the file by a build tool. So I wanted to add a flow type to assist developers in readability, and also that the object doesn't have all keys depending on the content of the underlying dataset, so the flow type would still document those optional keys.
Upvotes: 0
Views: 459
Reputation: 920
The shortest way to add a type definition to your problem is a cast in flow like the following:
export default ({ test: true }: {test: boolean});
Upvotes: 1