Declare a delegate type in Typescript

前端 未结 5 738
走了就别回头了
走了就别回头了 2021-01-30 10:12

Coming from a C# background, I want to create a datatype that defines a function signature. In C#, this is a delegate declared like this:

delegate v         


        
5条回答
  •  野性不改
    2021-01-30 10:43

    Five years and many, many TS versions later I find myself using a simpler type definition for declaring function types:

    type Greeter = (msg: string) => void;
    const someGreeter: Greeter = (msg: string) => `Hi there with ${msg}`;
    

提交回复
热议问题