#How can I avoid using any here

20 messages · Page 1 of 1 (latest)

copper bridge
import { Events } from "discord.js";
import CustomApplication from "./app";
import { EventType, EventOptions } from "../types";

export default class Event implements EventType {
    client: CustomApplication;
    name: Events;
    description: string;
    once: boolean;

    constructor(client: CustomApplication, options: EventOptions) {
        this.client = client;
        this.name = options.name;
        this.description = options.description;
        this.once = options.once

    }

    execute(...args: any): void {};
}
deep pikeBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
copper bridge

How can I avoid using any type in my execute function

Please ping me if you know the solution

mental quartz

by using the type that function is supposed to return

i dont know what that is because its not my code

copper bridge
mental quartz

? type for what

tough depot
import type { ClientEvents } from "discord.js";
import CustomClient from "../Classes/CustomClient/CustomClient.js";

export class Event<event extends keyof ClientEvents> {
    public readonly event: event;

    public readonly once?: boolean;
    
    public readonly run: (client: CustomClient, ...args: ClientEvents[event]) => Promise<any>;

    public constructor(eventData: Event<event>) {
        this.event = eventData.event;
        this.once = eventData.once;
        this.run = eventData.run;
    }
}

I use this if it helps, you can use the event name with djs's client events

copper bridge

so on every event i have to use ClientEvent

if i remove the any

right?

mental quartz

what..?

tough depot
smoky palm

You only have to use ClientEvents on the definition of your type/class. For the specific instances of events it would be inferred then

copper bridge

ty I fixed it kind off

smoky palm

You‘d probably need the Event generic on your EventOptions too to infer from name

copper bridge
smoky palm

Perfect