1

I am creating a configuration class, and I would like to add a property to assign any type of functions, with any return type and any number of parameters.

How can I declare this ?

I tried this:

export class ParamClass {
    param1: string;
    param2: string;
    onclick: (...args: any[]) => {};
}

This is working but the return type of the assigned method cannot be void.

1 Answer 1

2

You can just use any or unknown as the return type. Such a signature would accept void:

export class ParamClass {
    param1: string;
    param2: string;
    onclick: (...args: any[]) => unknown;
}

new ParamClass().onclick = () => { }

Play

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.