This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Andre Olive
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();
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Andre Olive
Andre Olive | Sciencx (2022-11-10T17:04:58+00:00) I Need help with typescript classes. Retrieved from https://www.scien.cx/2022/11/10/i-need-help-with-typescript-classes/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.