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

Type 'string' is not assignable to type 'SOME TYPE', small confusion when passing props

$
0
0

Below is how I am using my reusable component Badge made by me. It has types of props as follows but this gives some kind of error as:

enter image description here

Here is full code,

const variantsMap = {  done: "success",  processing: "info",  suspened: "warning",  cancelled: "error",};interface ITransactionProps {  status: "done" | "processing" | "suspened" | "cancelled";  label: string;}const MyComponent = ({ status, label }: ITransactionProps) => {  return <Badge variant={variantsMap[status]}>{label}</Badge>;};interface IBadgeProps {  variant: "success" | "info" | "warning" | "error";  children: string;}const Badge = ({ variant, children }: IBadgeProps) => {  return <div className={`badge bordered circular ${variant}`}>{children}</div>;};

How can this be solved in proper way? I would like to know all the ways if we can solve it in multiple ways.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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