Skip to content

Instantly share code, notes, and snippets.

@akaptur
Created December 14, 2021 01:04
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 akaptur/742fcba884c0fec83983b73f642a3252 to your computer and use it in GitHub Desktop.
Save akaptur/742fcba884c0fec83983b73f642a3252 to your computer and use it in GitHub Desktop.
type A = {
value: string;
kind: "a"; // here's the tag
};
type B = {
value: string;
kind: "b";
};
function my_func(a: A): string {
return a.value;
}
my_func({value: "hi", kind: "a"}); // no error, unsurprisingly
my_func({value: "hi", kind: "b"}); // now this *is* an error
my_func({value: "hi"}); // also an error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment