-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Typescript .throwUnlessCan()
, won't accept fields array as third parameter
#679
Comments
After understanding my mistake, I checked again the issues with a different approach and found this closed issue: I think there is too much ambiguity between the two functions and using the same signatures (allowing for arrays) could be a great improvement. Also, I spent so many hours looking for a good authorization library. Despite the fact that I reported this issue, I'm thankful I found this library. It's great, and handle most of what I could hope for.. Thank you! |
So, what are the expectations? Should it check that all fields can be accessed? |
Yes, I think it would be great. It would make the API less confusing. We can use a loop, it's no big deal, it's less elegant, but it's more of a clarity problem than an elegance one. It took me some time to realise my mistake. I would say it's a good possible design improvement. |
EDIT: I realised
.can()
ofPureAbility
(same asthrowUnlessCan()
) &.can()
ofAbilityBuilder
don't have the same signature.This is confusing. Now I'm wondering: If I want to check several fields access I need to do them one by one?
The problem:
.throwUnlessCan()
, won't accept field array as third parameter. It throws the following typescript error:TS2345: Argument of type 'string[]' is not assignable to parameter of type 'string'.
To reproduce:
Expected behavior
The third parameter
shouldcould acceptstring[]
alongstring
since the documentation states:I'm doing it wrong. Is this a possible improvements or is there a way to check several fields at once?
CASL Version
"@casl/ability": "6.1.1"
Environment:
Node v16.14.2
TS 4.6.4
The text was updated successfully, but these errors were encountered: