-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Invalid union type for subject when subjects have different actions #900
Comments
I’m thinking whether it’s actually an issue with types. Because if TS errors, then types are correct. And it seems as issue relates to IDE or typescript service inside IDE |
In many places to not repeat the same logic, I have this But indeed this can be improved. For example by creating an object map action => subject type + generic parameter on method: type ActionToSubjectTypeMap<T extends [string, unknown]> = {
[K in T[0]]: T extends any
? K extends T[0]
? T[1]
: never
: never
}
type PossibleAbilities =
| ['read', 'User']
| ['create' | 'delete', 'BlogPost']
type Mapping = ActionToSubjectTypeMap<PossibleAbilities> But I consider this as an improvement not a bug because TS fails to compile with the current behavior |
Describe the bug
The union type for
Subject
appears to be incorrect when different subjcts have different actions.To Reproduce
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.1The text was updated successfully, but these errors were encountered: