typescript lambda code example

Example 1: typescript arrow function

let sum = (x: number, y: number): number => {
    return x + y;
}

sum(10, 20); //returns 30

Example 2: arrow function in ts

// ES6: With arrow function  
var getResult = (username: string, points: number): string => {  
  return `${ username } scored ${ points } points!`;  
};

getResult('joyous jackal' , 100);

Example 3: typescript lambda type parameter

// For .ts (not .tsx)
const func = <T>() => { 
}

// For react Typescript (.tsx)
const func = <T,>() => {
}

// For older versions of react typescript
const func = <T extends unknown>() => {
  
}