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

前端 未结 8 1035
刺人心
刺人心 2020-11-30 17:19

Currently I have type definition as:

interface Param {
    title: string;
    callback: any;
}

I need something like:

inter         


        
8条回答
  •  孤街浪徒
    2020-11-30 17:25

    Hopefully, this will help...

    interface Param {
        title: string;
        callback: (error: Error, data: string) => void;
    }
    
    

    Or in a Function

    
    let myfunction = (title: string, callback: (error: Error, data: string) => void): string => {
    
        callback(new Error(`Error Message Here.`), "This is callback data.");
        return title;
    
    }
    
    

提交回复
热议问题