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

Is it possible to have a rest props for spread while using a react props interface with TypeScript?

$
0
0

I have this AppText component where I want to use a props interface while having the capacity to accept other props that I can consume with a spread operator, is it possible? Am I getting it wrong? Here is my attempt:

  • AppText
import React from "react";import { View, Text } from "react-native";import { colors } from "../utils/config";interface Props {  fontSize?: number;  color?: string;}const AppText: React.FC<Props> = ({  children,  fontSize = 16,  color = colors.black,  ...restProps}) => {  return (<Text {...restProps} style={{ color: color, fontSize: fontSize }}>      {children}</Text>  );};export default AppText;
  • How I am using my component :
<AppText accessible>Not member yet ? </AppText>    /*Type '{ children: string; accessible: true; }' is not assignable to type 'IntrinsicAttributes & Props & { children?: ReactNode; }'.Property 'accessible' does not exist on type 'IntrinsicAttributes & Props & { children?: ReactNode; }'*/

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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