Skip to content

Commit

Permalink
fix(ability): makes sure error for wrong Ability usage is thrown
Browse files Browse the repository at this point in the history
Relates to #334
  • Loading branch information
stalniy committed Jun 2, 2020
1 parent 2802cec commit db62daf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/casl-ability/src/PureAbility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ export class PureAbility<A extends Abilities = Abilities, Conditions = unknown>
const [action, subject, field] = args;
const rules: Rule<A, Conditions>[] = (this as any).possibleRulesFor(action, subject);

if (!this._hasPerFieldRules) {
return rules;
if (field && typeof field !== 'string') {
throw new Error('The 3rd, `field` parameter is expected to be a string. See https://stalniy.github.io/casl/en/api/casl-ability#can-of-pure-ability for details');
}

if (field && typeof field !== 'string') {
throw new Error('3rd, `field` parameter is expected to be a string. See https://stalniy.github.io/casl/en/api/casl-ability#can-of-pure-ability for details');
if (!this._hasPerFieldRules) {
return rules;
}

return rules.filter(rule => rule.matchesField(field));
Expand Down

0 comments on commit db62daf

Please sign in to comment.