Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Created September 10, 2019 13:18
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 iamandrewluca/689b4bc72e1970fabfa174556426c6e0 to your computer and use it in GitHub Desktop.
Save iamandrewluca/689b4bc72e1970fabfa174556426c6e0 to your computer and use it in GitHub Desktop.
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