Created
October 16, 2019 19:51
-
-
Save marcelmokos/7296ec857fd3d65ecbb8936ee48ede52 to your computer and use it in GitHub Desktop.
typing typescript functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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