Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

typescript function as parameter

function createPerson(name: string, doAction: () => void): void {
  console.log(`Hi, my name is ${name}.`);
  doAction(); // doAction as a function parameter.
}

// Hi, my name is Bob.
// performs doAction which is waveHands function.
createPerson('Bob', waveHands()); 
Comment

typescript pass a function as an argunetn

class Foo {
    save(callback: (n: number) => any) : void {
        callback(42);
    }
}
var foo = new Foo();

var strCallback = (result: string) : void => {
    alert(result);
}
var numCallback = (result: number) : void => {
    alert(result.toString());
}

foo.save(strCallback); // not OK
foo.save(numCallback); // OK
Comment

Parameter type from function TypeScript

//parameter
type Parameter<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
type paraMeterCheck = Parameter<(a: string, b: string) => void>;
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript keyof typeof 
Typescript :: how to get child element li beautifulsoup 
Typescript :: typescript value in enum 
Typescript :: loop type in typescript 
Typescript :: type script array 
Typescript :: push array elements if not exists mongoose 
Typescript :: concat type typescript 
Typescript :: available ports for localhost 
Typescript :: typescript make object optional 
Typescript :: How to check if all elements are equal C# 
Typescript :: input deno 
Typescript :: inno add exe in service 
Typescript :: update behaviorsubject value without emitting 
Typescript :: filter posts by meta value wordpress 
Typescript :: Warning: call_user_func_array() expects parameter 1 to be a valid callback 
Typescript :: how to add alias to my hosts in ansible hosts 
Typescript :: python ffmpeg convert ts to mp4 
Typescript :: typescript var global: typeof globalThis 
Typescript :: python remove all double elements from list 
Typescript :: Why do we use fragments in react? 
Typescript :: json to ts type 
Typescript :: ts factory pattern 
Typescript :: test coverage techniques 
Typescript :: mongodb nest.js 
Typescript :: ts Facade pattern 
Typescript :: Can only use lower 16 bits for requestCode registerForActivityResult 
Typescript :: dwayne johnson maui 
Typescript :: How to stop error reporting in TypeScript? 
Typescript :: detect incomming bullet from socket 
Typescript :: how to find the total of the products added to the shopping cart in java program 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =