Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Infer function prop input type typescript

$
0
0

I have a component (called Container) which has a renderHeader prop. The type of this prop is

(input: {    scrollY: Animated.Value    onLayout: (e: LayoutChangeEvent) => void    headerHeight: number  }) => JSX.Element

I have two ways to pass the prop. Either pass an inline arrow function or declare it somewhere and pass its name as prop.In the second one Typescript does not automatically infer the function's argument types. As there are several other props, using inline arrow functions make the code messy and less readable.

How can I use the approach below and make TS infer the function's argument types?

const renderHeader = ({ /* This argument's type should be inferred without explicitly defining it  */ }) => {}<Container renderHeader={renderHeader} />

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>