Witajcie, ostatnimi czasy piszę bota do komend, który ma być podpięty do bazy danych przez type-orm, więc tak piszę w typescript. Mam następujący kod
To jest mój interfejs:
export default interface iCommand {
args: Array<String>;
message: any;
client: any;
config: any;
new(args: String[], message: any): void;
runCommand(): void;
test(): void;
setClient(client: any): void;
setConfig(config: any): void;
}
To jest moja klasa implementująca interfejs.
Cały czas twierdzi, że coś żle implementuje interfejs:
import iCommand from './i-command';
export default class Voice implements iCommand {
args: String[];
message: any;
client: any;
config: any;
constructor(args: String[], message: any) {
this.args = args;
this.message = message;
this.client = {};
this.config = {};
}
test() {
console.log('run');
}
setClient(client: any) {
this.client = client;
}
setConfig(config: any) {
this.config = config;
}
runCommand(): void {
this.message.channel.send('Ping');
this.client.channels.get(this.config.infoChannelId).send('Pong');
}
}
Błąd jest taki:
Class 'Voice' incorrectly implements interface 'iCommand'.
Type 'Voice' provides no match for the signature 'new (args: String[], message: any): void'.ts(2420)\
Slownik komend:
import Voice from './voice';
export const Commands = {
'voice': Voice
}
A to jest manager, który zwraca przez nas pożądaną komendę
import {Commands} from './commands/commands';
import iCommand from './commands/i-command';
export default class CommandManager {
client: any;
config: any;
constructor(config: any) {
this.config = config;
this.client = {};
}
setClient(client: any) {
this.client = client;
}
getCommand(key, args, message): iCommand {
let command: iCommand = new Commands[key](args, message);
command.test();
command.setConfig(this.config);
command.setClient(this.client);
return command;
}
}
I dostaje taki blad:
commands_1.Commands[key] is not a constructor
oczywiście kod się wykonuje ale w oczy gryzie. Pracuje na windzie. Ktoś wie dlaczego to nie dziala?