Which means the following as a type :() => void = null

I am considering these two function declarations:

function f1(chainFn: (fn: Function) => void = null) {

}

function f2(): (...args: any[]) => (cls: any) => any {

}

I do not understand what the following parts define:

// function that accepts `fn` of Function type by returns what?
(fn: Function) => void = null

// function that accepts an array of arguments and returns a function that returns a result of `any` type?
(...args: any[]) => (cls: any) => any

Can someone refine and provide examples of specific implementations?

+4
source share
2 answers

The first function f1takes an argument chainFn, and this is a function that takes a function as a parameter fnand returns nothing => void, also this parameter chainFnis optional = nullwith an undefined runtime value.

f2 . ...args:any[] ( var r = f2(); r(1,2,3,4);), , -.

+6
() => void

, .

() => void = null

.

f(g: () => void = null) { ... }

, g () => void null , . .

, , JavaScript undefined not null , , .

// g is optional and will be undefined if not provided
f(g?: () => void) { ... }

// g is optional and will be a no-op if not provided.
f(g: () => void = () => {}) { ... }
+5

Source: https://habr.com/ru/post/1667846/


All Articles