DekGenius.com
TYPESCRIPT
ts declare function type
type GreetFunction = (a: string) => void;
types function typescript
interface Safer_Easy_Fix {
title: string;
callback: () => void;
}
interface Alternate_Syntax_4_Safer_Easy_Fix {
title: string;
callback(): void;
}
typescript type of a function
onSubmit: () => void;
onSubmit: (value: string) => void;
typescript function
// Parameter type annotation
function greet(name: string): string {
return name.toUpperCase();
}
console.log(greet("hello")); // HELLO
console.log(greet(1)); // error, name is typed (string)
Function in Typescript
function sumNumbers(num1:number,num2:number):number{
return num1*num2;
}
const total = sumNumbers(2,4
typescript function type
interface getUploadHandlerParams {
checker : Function
}
types function typescript
interface Param {
title: string;
callback: function;
}
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>;
types function typescript
interface Easy_Fix_Solution {
title: string;
callback: Function;
}
typescript function type
interface Date {
toString(): string;
setTime(time: number): number;
// ...
}
typescript function
// Named function
function add(x: number, y: number): number {
return x + y;
}
// Anonymous function
let myAdd = function (x: number, y: number): number {
return x + y;
};
typescript function type
// define your parameter's type inside the parenthesis
// define your return type after the parenthesis
function sayHello(name: string): string {
console.log(`Hello, ${name}`!);
}
sayHello('Bob'); // Hello, Bob!
types function typescript
interface Alternate_Syntax_4_Advanced {
title: string;
callback<T extends unknown[], R = unknown>(...args?: T): R;
}
types function typescript
interface Better_still_safe_but_way_more_flexible_fix {
title: string;
callback: <T = unknown, R = unknown>(args?: T) => R;
}
interface Alternate_Syntax_4_Better_still_safe_but_way_more_flexible_fix {
title: string;
callback<T = unknown, R = unknown>(args?: T): R;
}
declare type function typescript
function printToConsole(s: string) {
console.log(s);
}
typescript function
export const multiply_by7 = (x:number):number =>{return x*7}
© 2022 Copyright:
DekGenius.com