Skip to content

Omit is breaking in gaurd #32030

Closed
Closed
@stavalfi

Description

@stavalfi

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions