Skip to content

Instantly share code, notes, and snippets.

@snoble
Created December 24, 2021 19:41
Show Gist options
  • Save snoble/e82bdf1212792febb16cf64d92152929 to your computer and use it in GitHub Desktop.
Save snoble/e82bdf1212792febb16cf64d92152929 to your computer and use it in GitHub Desktop.
type T = {x: string, y: string} | {a:string, b: string}
function fn(a: T) {
if('x' in a) {
return a.y
} else {
return a.b
}
}
console.log(fn({x: 'xx', a: 'aa', b: 'bb'}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment