Reputation: 1
I have a javascript function:
function foo(obj: Object): any { return 42; }
I want to make sure the input object has a property named 'name' on it, how can I do that with flow?
Upvotes: 0
Views: 1255
Reputation: 213
Using {name: string}
will assert that any object that comes in to the function must have a name
property whose value is a string:
function foo(obj: {name: string}): any { return 42; }
Because Flow represents object types structurally, you can pass any object that has at least a name
property to this annotation.
Upvotes: 5