Someone may help me?
I'm learning typescript and I have some trouble with classes.
here's my code:
Command Class
import Diagram from "../diagram/Diagram";
import MainEngine from "../MainEngine";
import { CommandData } from "../managers/CommandManager";
import User from "../core-models/UserModel";
export default abstract class Command<D>{
function: Function;
data: D;
user: User;
engine: MainEngine
diagram: Diagram
constructor(commandData:CommandData){
this.function = async () => {};
this.data = commandData.data;
this.user = commandData.user;
this.engine = commandData.session._engine;
this.diagram = commandData.session._diagram;
}
public async execute(){
await this.function();
}
}
and This CommandGetVncUrl that extends Command
import Command from "./Command";
import { CommandData } from "../managers/CommandManager";
import ResponseCommand from "./ResponseCommand";
export default class CommandGetVncUrl extends Command<any>{
constructor(commandData:CommandData, response:ResponseCommand){
super(commandData);
this.function = async () => {
try {
const device = this.diagram.selectDeviceById(this.data);
if(device){
const url = await this.engine._cloudMngr.getConsoleUrl(device.getDeviceData(), this.user);
response.setData({url}).send();
}
} catch (error) {
throw Error();
}
}
}
}
when I call the function .execute() I have this error:
Property 'execute' does not exist on type 'CommandGetInstanceStatus | CommandDiagramLoad | CommandCreateInstance | CommandChangeDevicePosition | ... 10 more ... | CommandReboot'.
Property 'execute' does not exist on type 'CommandCreateLink'.
74 await this.make(commandData)[commandData.command].execute();
Top comments (2)
The object instance stored in
this.make(commandData)[commandData.command]
doesn't have theexecute()
it's trying to call. Slap a breakpoint in that line and inspect the value returned bythis.make(commandData)
. You may have to split it up in a few lines to make it easier to debug. I.e.:You definitely have way more code that is involved with your problem that you show here. Try to create simpler example that reproduce your problem or show your whole code on website like GitHub.