Created
May 16, 2019 18:42
-
-
Save GingerBear/9d4f4209b396e3e4e547538bcde12c3b to your computer and use it in GitHub Desktop.
return different type based parameter with overloads
This file contains hidden or 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 foo(): null; | |
function foo(a: number): string; | |
function foo(a?) { | |
if (typeof a === 'number') { | |
return '123'; | |
} else { | |
return null; | |
} | |
} | |
const a = foo(); // null | |
const b = foo(123); // string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment