Skip to content

Instantly share code, notes, and snippets.

@jwalsh
Created January 4, 2018 21:52
Show Gist options
  • Select an option

  • Save jwalsh/ab42cbb8dc4be30e36471b3678609fad to your computer and use it in GitHub Desktop.

Select an option

Save jwalsh/ab42cbb8dc4be30e36471b3678609fad to your computer and use it in GitHub Desktop.
let u1: number | string | boolean = 1;
console.log(u1);
let u2 = 1 | 2;
console.log(u2);
// The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
// let u3 = 'A' | 'B';
interface A {
message: string;
}
interface B {
message: string;
}
// No error
let u4: A | B = {
message: "Test"
};
console.log(u4);
// error TS2322: Type '{ error: string; }' is not assignable to type 'A | B'.let u5: A | B = {
error: "Test"
};
console.log(u5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment