I've got a function inside of react (using typescript), where a container component is passing down variables to a child component. The variables are functions. However, when I'm passing these down, i get the "noImplicitAny" error. zoomIn and zoomOut are functions, and rest seems like an array. How should I assign a type to zoomIn, zoomOut, and ...rest?
<TransformWrapper>
{({ zoomIn, zoomOut, ...rest }) => (
<TransformComponent>
<Something onClick={zoomIn} />
<TransformComponent/>
)}
The type of a function can be
Function
to match any function, but it's better to specify the parameter and return types like so:myFunc: (p1: type1, p2: type2) => returnType
In the case of something like
zoomIn
it's probably() => void
.As for
rest
, you could set the type asany[]
, though there may be a better type - it's unclear from the limited code sample provided. Remember though that the error is 'no implicit any', meaning you can make it an explicit any if you want.