You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceProject{projectId: string}interfaceOrganization{organizationId: string}typeProjectOrOrganization=Project|OrganizationfunctionfindTask(query: ProjectOrOrganization){// Tasks.find(query)}findTask({projectId: 'foo'})// should workfindTask({organizationId: 'bar'})// should workfindTask({projectId: 'foo',organizationId: 'bar'})// should not work, but doesfindTask()// 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.
The text was updated successfully, but these errors were encountered:
A type T is assignable to a union type U if T is assignable to at least one of the constituents of U. In your example, the type { projectId: string, organizationId: string } is assignable to both of the constituents and therefore assignable to the union type. Unions don't imply exclusivity among the types, but if you really want to ensure that a type doesn't have a specific member, you can define that member as an optional property of some marker type that never occurs in the wild:
TypeScript Version: 2.0.0
Code
Expected behavior:
findTask({ projectId: 'foo', organizationId: 'bar' })
should not workExpected 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.
The text was updated successfully, but these errors were encountered: