I have a Tool type like so
type Tool = {
icon: JSX.Element;
toolEnum: ClipsToolsEnum;
tooltip: string;
isDisabled:
| ((workspaceId: string, currentSrc: string) => boolean)
| (() => boolean)
| ((length: number) => boolean);
};
the isDisabled property should be a function that returns a boolean. But the function arguments can be of multiple type. It can have no arguments, one argument of type number or two arguments of type string. I tried to make it work but I couldnt.
I run a map on Tool array and there is a Button in there where I would use that function
<Button
variant={'outline'}
size={'icon'}
className='size-12'
disabled={(() => {
switch (tool.toolEnum) {
case ClipsToolsEnum.RESET:
return tool.isDisabled(workspaceId, '');
case ClipsToolsEnum.MERGE:
return tool.isDisabled(length);
case ClipsToolsEnum.DELETE:
return tool.isDisabled(length);
case ClipsToolsEnum.FINISH:
return tool.isDisabled(length);
case ClipsToolsEnum.OPEN:
return tool.isDisabled();
}
})()}
onClick={() => handleToolClick(tool.toolEnum)}
>
{tool.icon}
</Button>
Showing error
"Expected 2 arguments, but got 1.ts(2554)
ClipsTools.tsx(50, 30): An argument for 'currentSrc' was not provided.
(property) isDisabled: (arg0: never, currentSrc: string) => boolean"
It looks as if it expects it to be always the function with two arguments with this implementation.