Skip to content

Instantly share code, notes, and snippets.

@dmitry-a-morozov
Created February 25, 2016 00:54
Show Gist options
  • Save dmitry-a-morozov/47ce5ca63541085258f5 to your computer and use it in GitHub Desktop.
Save dmitry-a-morozov/47ce5ca63541085258f5 to your computer and use it in GitHub Desktop.
class C1 { item: string }
class C2 { item: string[] }
class C3 { item: string }
type C1_C2_C3 = C1 | C2 | C3;
function Foo(x: C1_C2_C3): string {
if (x instanceof C1) return x.item;
else if (x instanceof C2) return x.item[0];
else if (x instanceof C3) return x.item;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment