score:2
Accepted answer
depends how much of childprops
you want to reuse.
if you want to reuse just a couple of properties, you can use in indexed type query to get the type of a specific property:
interface parentprops {
onchange: childprops['onchange']
}
or you can define parentprops
to extend childprops
if you want to reuse all properties:
interface parentprops extends childprops {
}
or you can pick just a subset using pick
:
interface parentprops extends pick<childprops, 'onchange'> { // pick<childprops, 'onchange' | 'label'> to pick more
}
or if you want to pick all except a subset you can use omit
interface parentprops extends omit<childprops, 'label'> { // omit<childprops, 'onchange' | 'label'> to omit more
}
Source: stackoverflow.com
Related Query
- A proper way to reuse existing type definitions
- What's the proper way of giving react stateless functional component a typescript type
- Proper way of using React hooks + WebSockets
- Correct way to type nullable state when using React's useState hook
- What's the proper way of passing a ref to a prop?
- Proper Way to Make API Fetch 'POST' with Async/Await
- Proper way to navigate with React Native, Redux, and Navigator
- Is there any proper way to integrate d3.js graphics into Facebook React application?
- Proper way to use react-hook-form Controller with Material-UI Autocomplete
- Proper TypeScript type for creating JSX element from string
- Proper way of using WebSockets with React Native
- Proper Flow type for React render method?
- What's the proper way of binding touchstart on React JS?
- What is the proper way to use React Memo with Flow?
- Proper way to inject React Component onto page in Chrome Extension?
- Create-react-app + TypeScript + CSS Modules: Auto-generating type definitions without ejecting from CRA
- Scalable way of handling font definitions in React.js application
- Adding type definitions to an HOC which injects props into a component
- Invariant Violation in React Render OR the proper way to iterate and return in React
- Draft.JS: the proper way to detect content change
- what is the proper way to publish a React component module in NPM without external dependencies inside?
- Proper way to initialize data
- Proper way to load WASM module in React for big files (more than 4kb)
- Proper way to implement jwplayer in react component using webpack (react-starter-kit)
- Proper way of handling conditional component render depending on route?
- Proper way to include a .js file in gatsby which executes its code on all the pages
- Dispatch actions the proper way
- What is the proper way to enable the css prop in Emotion 11/Next js 10 apps
- Proper way to pop from a react component's array-type state attribute?
- Type definitions for Redux (Toolkit) store with preloadedState
More Query from same tag
- Remove duplicates in array list react
- How to use function containing setState synchronously
- I want pass book data to the view page to the edit page in react js
- Change behavior of Steps React component from Ant Design(https://ant.design/components/steps/)
- React, passing data detail on target element
- Typescript Error on super(): expected 1-2 arguments, but got 0
- Not setting state with data get back from fetch call
- How to convert FormData into Object then JSON.stringify that?
- Tabs with FlatLists inside ScrollView - like Instagram or Twitter profile pages
- JavaScript Input not allowing decimals
- Javascript (React.js) - Refactor a switch-case
- My component is trying to access data that doesn't exist yet, "Cannot read property 'data' of undefined"
- React: Error referencing a function within state
- Pause function is being called inside react component but nothing happens
- Conditionally display input field
- ReactJS onClick get DIV IDs
- is onTouchStart exactly equivalent to onMouseDown and onTouchEnd exactly equivalent to onMouseUp?
- How can I measure wasted renders in React 16?
- Fragments giving Unexpected token error in React 16.2
- How to add css class based on function in React / Next js?
- Why my class method works in React without explicitly binding it to 'this'?
- Dynamically spread setState doesn't work on ternary operator spread
- Webpack has been initialised using a configuration object that does not match the API schema. webpack install by "npm install webpack"
- React Memo Renders Every Time with same given props
- React JS mapping an array inside a state array
- page going blank in react, from obtaining information about user in firebase
- Cross-Origin Request Blocked with google oauth in react and deno
- How to select the rows of a material table programmatically on onclick event of button -React js
- How can I get total price of all product in cart in Reactjs
- Reactjs Passing props down 2 components