Tengo este componente AppText en el que quiero usar una interfaz Props mientras tengo la capacidad de aceptar otros campos de accesorios que puedo consumir con un spread operator . Aquí está mi intento a continuación.
Texto de aplicación:
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;Cómo estoy usando mi componente:
<AppText accessible>Not member yet ? </AppText>El error que estoy recibiendo:
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; }'Debería poder redefinir Props , supongo que TextProps se puede importar desde react-native , así:
interface Props extends TextProps { fontSize?: number; color?: string; } Esto agrega TextProps a sus propiedades, el operador de propagación debe comprender qué elementos sobran.