Skip to content

XOR in union allows both #10575

Description

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 Ryan Cavanaugh (@RyanCavanaugh)

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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