I am trying to declare the type of a function that can take function or object as a parameter, but the result is Cannot call `data` because a callable signature is missing in `TestObject` [1].
This is basic code example what I trying to achieve.
type TestObject = {
name: string
}
const dummyFunction = (data: TestObject | (props:Object)=> TestObject) => {
typeof data === 'function' ? props => data(props): data;
return {} // empty object just for the test purpose
}
or link to flow-type
What I am missed?
typeof data === 'function' ? data : () => data
if you're trying to normalize it to a function?data(props)
is the issue, because in that part of the ternary,data
is an object and not a function.props => data(props)
doesn't do anything. You create a function that is never executed or returned. And since that bit is exactly what giving you the error, it'll help to know what you're trying to do there.TestObject
type isn't mutually exclusive with a function, so thedata === 'function'
isn't enough to determine that you're not dealing with aTestObject
.