I would like to implement the following (in React/TypeScript (.tsx))
Main.tsx (edit: botCommands is an array in which multiple objects can be (with command and botResponse())
function Main() {
return (
<TestComponent
botVariables={{
tasks: [],
groups: []
}}
botCommands={[
{
command: "-help",
botResponse(botVariables) {
return botVariables.tasks[0]
}
}
]}
/>
);
}
TestComponent.tsx
interface BotCommand {
command: string;
botResponse(botVariables: any): string;
}
interface TestComponentProps {
botVariables: any;
botCommands: BotCommand[];
}
export default function TestComponent(props: TestComponentProps) {
return (
// magic
);
}
in Main.tsx I would like that in the function botResponse() the type (currently any) is automatically adjusted. So that automatically the content of botVariables is taken as type.
Simply put, if I write in Main.tsx in the botResponse() function "botVariables."
that tasks and groups can be suggested to me by the IDE. The data in botVariables can change so you can't just create an interface in the TestComponent.tsx file.
I tried with typescript generics but unfortunately failed. Thanks for help!
botVariables? Is it always an object with propertiestasksandgroupswhich are arrays? Do the contents of atasksarray vary, or are they alwaysstring?