Created
September 10, 2019 13:18
-
-
Save iamandrewluca/689b4bc72e1970fabfa174556426c6e0 to your computer and use it in GitHub Desktop.
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
type Test = { | |
foo: number | |
returnString?: boolean | |
} | |
function test(): number | |
function test(arg: Omit<Test, 'returnString'>): number | |
function test(arg: Test & { returnString: false }): number | |
function test(arg: Test & { returnString: true }): string | |
function test(arg: Test = { foo: 2 }): number | string { | |
if (arg && arg.returnString) { | |
return '' | |
} | |
return 0 | |
} | |
const t1: number = test() | |
const t2: number = test({ | |
foo: 1 | |
}) | |
const t3: number = test({ returnString: false, foo: 1 }) | |
const t4: string = test({ returnString: true, foo: 2 }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment