Closed
Description
TypeScript Version: 3.5.2
Search Terms: Omit, guard
Code
type t1 = { a: boolean } & ({ x: number } | { y: string } | {})
const z1: t1 = Date.now() === 123453 ? { a: true, x: 1 } : { a: true }
const z2: Omit<t1, 'a'> = z1
console.log('x' in z2 && z2.x)
Expected behavior:
no errors
Actual behavior:
Error:(235, 29) TS2339: Property 'x' does not exist on type 'never'.
Playground Link:
Link to Playground
If I specify the actual type instead of using Omit, everything is working with no errors:
type t1 = { a: boolean } & ({ x: number } | { y: string } | {})
const z1: t1 = Date.now() === 123453 ? { a: true, x: 1 } : { a: true }
const z2: { x: number } | { y: string } | {} = z1
console.log('x' in z2 && z2.x)