score:5
i was able to do this in ts 2.3. the point is to use 2 types for "inside" and "outside" of that component.
interface iprops<v> {
value: v;
dosomething(val: v): void;
}
// type "inside" component
function _comp<t>(props: iprops<t>) {
return <div />;
}
// type for "outside" of component
interface genericssfc extends react.sfc<any> {
<t>(props: iprops<t> & { children?: react.reactnode }, context?: any): jsx.element;
}
const comp = _comp as genericssfc;
// dont type check: v is of type "hey"
<comp value={"hey"} dosomething={v => v - 1} />;
Source: stackoverflow.com
Related Query
- Typescript React stateless function with generic parameter/return types
- Passing a function as a prop with different parameter types in React with Typescript
- React with TypeScript - define defaultProps in stateless function
- React prop types with TypeScript - how to have a function type?
- How to test with jest and typescript with types a basic react function component
- TypeScript compiler error with React Stateless Function component
- Typescript React component with function overload and generic params
- Typescript types of composition Ramda lens with React useState set function
- How to create a generic arrow function with react and typescript
- How to implement a generic arrow function as interface property in Typescript with React JSX
- Typescript throws an explicit function return type error when using Suspense with React Router
- Allow passing a function with extended interface as parameter in React + Typescript
- Set types on useState React Hook with TypeScript
- What is the TypeScript return type of a React stateless component?
- Type of Generic Stateless Component React? OR Extending generic function interface in typescript to have a further generic?
- Using React forwardRef with Typescript generic JSX arguments
- Typescript with React - use HOC on a generic component class
- React passing parameter with arrow function in child component
- How to use jest.spyOn with React function component using Typescript
- How do you correctly use React.lazy() in Typescript to import a react component with a generic type parameter?
- Test return value of function with Jest in React
- optional react useState types with jsdoc, typescript checkjs (javascript)
- Generic React TypeScript component with 'as' prop (able to render any valid dom node)
- Is it possible to type a React function component with TypeScript without using arrow functions?
- Function return type mismatching with TypeScript
- Why can't a react stateless function return an array?
- TypeScript React HOC return type compatible with decorator
- Typescript type issue in map function of mixed types react
- Generic TypeScript API with types as parameters
- Typescript - A function which returns a function with generic type - what does it do?
More Query from same tag
- React - refetch child component data when the props change
- Condition inside setInterval in functional component
- Is there a way to link to a new page with react router?
- How to get VSCode to not check other .ts files in directory for variable conflicts?
- How to make a request to an API route from `getStaticProps`
- React - Styled Component change with Click
- Add onClick Event to <tr> in React
- Fontawesome icons React
- Why isn't React re-rendering the page after the state is changed?
- Error when show API data. Warning: Each child in a list should have a unique "key" prop
- Passing Environment variables to React application from Package.json
- React Hook Form - Resetting "isDirty" without clearing form?
- Fill array with random picture from url that gives random picutres
- How to map array of objects to ej2 syncfusion data grid
- Use queried data from GraphQL in component
- Using IndexRoute to set up a Landing Page in my React App
- The current testing environment is not configured to support act(...) - @testing-library/react
- React.js setState issue
- @react-google-maps Marker LatLng throwing error
- React and Redux losing State
- Why is the GraphQL input type breaking the app
- react-redux Component failing to load at the first API call
- Fetching all users from mongo returns empty object React Meteor
- Why is a .git folder automatically being created when creating a react app?
- Property 'dispatch' is missing in type error when passing root store to root component
- Using React, how can I attach a click event to a class or ID?
- How to close webview after the work is done in react native
- how to render components based on the value of props?
- slice function applied on undefined
- Deploying React app with Parcel build on Github Pages