ts define function type code example
Example 1: typescript function
function greet(name: string): string {
return name.toUpperCase();
}
console.log(greet("hello"));
console.log(greet(1));
Example 2: typescript function type
function sayHello(name: string): string {
console.log(`Hello, ${name}`!);
}
sayHello('Bob');
Example 3: typescript function type
interface Date {
toString(): string;
setTime(time: number): number;
}
Example 4: simple function in typescript
function add(x: number, y: number): number {
return x + y;
}
let myAdd = function (x: number, y: number): number {
return x + y;
};
Example 5: types function typescript
interface Alternate_Syntax_4_Advanced {
title: string;
callback<T extends unknown[], R = unknown>(...args?: T): R;
}