Declaring a Typescript Function Type

Ole Ersoy
1 min readApr 8, 2020
Image by Okan Caliskan from Pixabay

Updated Version

There’s an updated version of this article here:

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

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

Brought To You By

--

--