Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
typing typescript functions
function add(a: number, b: number): number { return a + b };
const add = (a: number, b: number): number => a + b;
type Arithmetics = (a: number, b: number) => number;
// or
/*
interface Arithmetics {
(a: number, b: number): number;
}
*/
const addition: Arithmetics = add;
add(1, 2); // 3
const multiplication: Arithmetics = (a, b) => a * b;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment