Issue
interface GetAmountProps {
value: undefined | string
}
const getAmount = (value: GetAmountProps): string => {
if (value === undefined) return '(0)';
return value;
};
export default getAmount;
Why do I have an error on the line with return value;
?
Type 'GetAmountProps' is not assignable to type 'string'.
Solution
The way you have it defined, a value of value
would be:
{
value: "banana"
}
Notice that this is any object with the property "value" of stype string
You probably meant
type GetAmountProps = undefined | string;
or
const getAmount = ({value}: GetAmountProps): string => {
if (value === undefined) return '(0)';
return value;
};
which is called like
getAmount({ value: "banana" });
Answered By - Samathingamajig
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.