score:2
you can export childprops
, then in parent use indexed access operator to get the type of the foo
prop:
const foo: childprops['foo'] = str => {
console.log(str);
}
or even without exporting child props type, you can use componentprops
utility to get it:
import { componentprops } from 'react';
const foo: componentprops<typeof child>['foo'] = str => {
console.log(str);
}
Source: stackoverflow.com
Related Query
- Reusing types for functions in React + TypeScript
- Typescript types for React checkbox events and handlers?
- TypeScript types for React component where prop is an array of objects?
- Are these two types of updater functions for setState in React equal?
- Correct Typescript types for Firebase in a React app
- React types files not working in React TypeScript (.tsx) file - Throwing ESLint errors for React Component
- Conditional types for a dynamic React component in Typescript
- TypeScript errors in React Class Component property does not exist on type 'Readonly<{}>', not sure how to set types for state
- React Typescript types for monaco-editor
- How to define Typescript properties and types for a React Action Hook Store
- React 15, Typescript 2.2.1. How to cast types for functional/stateless components?
- Explicit types in React Typescript for custom global state hook
- How to install react beta types for typescript project?
- TypeScript types for passing a React component to React.cloneElement
- How to declare type for functions that receives data from React Child components in TypeScript
- Suggest correct TypeScript for React wrapper function which adds 2 functions to wrapped component's props
- Typescript type for passing functions and react components
- React PropTypes: Allow different types of PropTypes for one prop
- Typescript react - Could not find a declaration file for module ''react-materialize'. 'path/to/module-name.js' implicitly has an any type
- Set types on useState React Hook with TypeScript
- How to specify (optional) default props with TypeScript for stateless, functional React components?
- TypeScript workaround for rest props in React
- React and TypeScript—which types for an Axios response?
- What is the react-app-env.d.ts in a react typescript project for
- How do I create a TypeScript type definition for a stateless React component?
- React prop types with TypeScript - how to have a function type?
- Can I use arrow functions instead of normal functions for React Hooks?
- How to organize types definitions in a React Project w/ Typescript
- Typescript for Facebook React
- Where to declare auxiliar functions for a React functional component. Inside or outside?
More Query from same tag
- Why does react form's onSubmit fire after every keystroke, how to use enter button to submit form?
- How to call from parent component child function in react, typescript and redux
- How to use my index as the key when using immutability helper`update`
- How can I change the value of an object in react based on form data input by the user?
- I can't get Firebase to work on my React project
- Setting dynamic speed for scroll in react
- Function is getting called multiple times
- Update PWA icon on android
- Recharts: Setting X-Axis Label Margin
- Access child components data without re-rendering parent
- How to handle onChange in Typescript
- Error: Cannot call useFirebaseApp unless your component is within a FirebaseAppProvider
- False Positives with React Flow
- React: Problem in dynamic nested routing. How to solve this error?
- Why is my nginx routing my react app static files to my index.html
- Webpack - Prevent file duplication with webpack code splitting & react-loadable
- Each child in a list should have a unique "key" prop. I made it, but still see this error
- How to fix problem with z-index and overflow:scroll
- Getting an error .map() is not a function
- Semantic UI styled issue
- Import Local image from object in React
- React functional component using the `useState` hook does not update onChange using ReactiveSearch
- React.createClass is not a function, may be webpack compling error
- How to import/add multiple images as per JSON key value in ReactJS?
- Unexpected behaviour : function vs functional component and animations
- filtering select drop down menu to filter in React?
- startsWith only working for first condition
- How can I load multiple images with Next Image from a loop?
- jest test results after fireEvent.click() (without enzym)
- React - How to access props without using constructor