I'm attempting to define what arguments must be passed to a function in React with Typescript:
type IncrementDecrementFunctionArgs = {
id: number;
amount: string;
foo: string;
};
export const dummyProps = {
increment: function({ id, amount }: IncrementDecrementFunctionArgs) {
console.log("increment ", id, " by amount: ", amount);
}
}
Props are spread into component:
<Component {...dummyProps} />
Component calls function:
const handleClick = (val: incrementDecrement) => {
if (val === incrementDecrement.increment) {
increment({ id, amount });
} else {
decrement({ id, amount });
}
};
I can't work out why this isn't erroring. foo does not exist. id is a string and amount is a number.