Skip to content

XOR in union allows both #10575

Closed
Closed
@jakobrosenberg

Description

@jakobrosenberg

TypeScript Version: 2.0.0

Code

interface Project { projectId: string }
interface Organization { organizationId: string }

type ProjectOrOrganization = Project | Organization

function findTask(query: ProjectOrOrganization) {
    // Tasks.find(query)
}

findTask({ projectId: 'foo' })
// should work

findTask({ organizationId: 'bar' })
// should work

findTask({ projectId: 'foo', organizationId: 'bar' })
// should not work, but does

findTask()
// should not work

Expected behavior:
findTask({ projectId: 'foo', organizationId: 'bar' }) should not work
Expected behavior based on a post by @RyanCavanaugh

Actual behavior:
findTask({ projectId: 'foo', organizationId: 'bar' }) works

@RyanCavanaugh wrote a reply here which implies that or-unions work as XOR.

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