Skip to content

Instantly share code, notes, and snippets.

@tail-call
Created October 17, 2022 04:24
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 tail-call/0b7711556e67920b2d6fdabc31d77b99 to your computer and use it in GitHub Desktop.
Save tail-call/0b7711556e67920b2d6fdabc31d77b99 to your computer and use it in GitHub Desktop.
interface X {
x: any;
}
interface Y {
y: any;
}
interface Z {
z: any;
}
function f(x: X): Z;
function f(y: Y): Z;
function f(xOrY: X | Y): Z {
if ('x' in xOrY) {
return { z: xOrY.x };
} else {
return { z: xOrY.y };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment