Skip to content

Instantly share code, notes, and snippets.

@marcelmokos
Created October 16, 2019 19:51
Show Gist options
  • Save marcelmokos/7296ec857fd3d65ecbb8936ee48ede52 to your computer and use it in GitHub Desktop.
Save marcelmokos/7296ec857fd3d65ecbb8936ee48ede52 to your computer and use it in GitHub Desktop.
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