close

How to define type for a function callback (as any function type, not universal any) used in a method parameter

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to define type for a function callback (as any function type, not universal any) used in a method parameter in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to define type for a function callback (as any function type, not universal any) used in a method parameter ?

  1. How to define type for a function callback (as any function type, not universal any) used in a method parameter ?

    define type for a function callback (as any function type, not universal any) used in a method parameter Additionally, if you intend to invoke this callback with 0 arguments and will ignore its return value, the type () => void matches all functions taking no arguments.

  2. define type for a function callback (as any function type, not universal any) used in a method parameter

    define type for a function callback (as any function type, not universal any) used in a method parameter Additionally, if you intend to invoke this callback with 0 arguments and will ignore its return value, the type () => void matches all functions taking no arguments.

Method 1

The global type Function serves this purpose.

Additionally, if you intend to invoke this callback with 0 arguments and will ignore its return value, the type () => void matches all functions taking no arguments.

Method 2

Following from Ryan’s answer, I think that the interface you are looking for is defined as follows:

interface Param {
    title: string;
    callback: () => void;
}

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment