I Need help with typescript classes

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/CommandMana…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » I Need help with typescript classes." Andre Olive | Sciencx - Thursday November 10, 2022, https://www.scien.cx/2022/11/10/i-need-help-with-typescript-classes/
HARVARD
Andre Olive | Sciencx Thursday November 10, 2022 » I Need help with typescript classes., viewed ,<https://www.scien.cx/2022/11/10/i-need-help-with-typescript-classes/>
VANCOUVER
Andre Olive | Sciencx - » I Need help with typescript classes. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/10/i-need-help-with-typescript-classes/
CHICAGO
" » I Need help with typescript classes." Andre Olive | Sciencx - Accessed . https://www.scien.cx/2022/11/10/i-need-help-with-typescript-classes/
IEEE
" » I Need help with typescript classes." Andre Olive | Sciencx [Online]. Available: https://www.scien.cx/2022/11/10/i-need-help-with-typescript-classes/. [Accessed: ]
rf:citation
» I Need help with typescript classes | Andre Olive | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.