Skip to content

Instantly share code, notes, and snippets.

@vogler
Created October 8, 2019 23:20
Show Gist options
  • Save vogler/d80e7045b008c23347650b82b36d133a to your computer and use it in GitHub Desktop.
Save vogler/d80e7045b008c23347650b82b36d133a to your computer and use it in GitHub Desktop.
type a = { id: number, name: string, foo: string }
type b = { id: string, name: string, bar: string }
type c = a | b
type d = a & b
type id = d['id'] // number & string = never (bot)
const va: a = {id: 1, name: 'ha', foo: 'foo'}
const vb: b = {id: '1', name: 'ha', bar: 'bar'}
const vc1: c = va
const vc2: c = vb
const vc3/*: c*/ = { ...va, ...vb }
const vd: d = vc3 // error message could be better; there is no value satisfying d since id: never
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment