Declaring a Typescript Function Type | Task

Ole Ersoy
Feb - 19  -  1 min

Scenario

We want to declare the function return type of our Typescript higher order function (Function that returns a function).

Approach

As an example we will declare the Angular Schematics Rule type:

declare type Rule = (tree: Tree, context: SchematicContext) =>
Tree | Observable<Tree> | Rule | void;

Now we can declare our function return type:

function returnRule():Rule }{...}

Demo

Bonus

Bonus

/**
 * A type for a function that accepts multiple number arguments
 * and returns a number.
 */
export declare type NArgFunction = (parameters:number[])=>number