Skip to content

Instantly share code, notes, and snippets.

@GingerBear
Created May 16, 2019 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GingerBear/9d4f4209b396e3e4e547538bcde12c3b to your computer and use it in GitHub Desktop.
Save GingerBear/9d4f4209b396e3e4e547538bcde12c3b to your computer and use it in GitHub Desktop.
return different type based parameter with overloads
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