#900·casl

[Bug] Invalid union type for subject when subjects have different actions

Author: douglasg14bCreated Mar 30, 2024Updated Mar 30, 2024
Labelsenhancement

Describe the bug

The union type for Subject appears to be incorrect when different subjcts have different actions.

To Reproduce

typescript
type Abilities = ["create" | "manage", "campaign"] | ["create" | "delete", "user:invite"]

const ability = createMongoAbility<Abilities>();

// Intellisense suggests this, but TS actually errors indicating this is incorrect (which it is)
ability.can('delete', 'campaign')

// This is correct
ability.can('delete', 'user:invite')

image

Expected behavior

The union type for subject should be impacted by the action, and not suggest subjects that are not valid for a given action.

CASL Version

@casl/ability: 6.7.1