From db62dafee3b9d1db08ab49edbcfe0209a34584ae Mon Sep 17 00:00:00 2001 From: Sergii Date: Tue, 2 Jun 2020 19:20:01 +0300 Subject: [PATCH] fix(ability): makes sure error for wrong `Ability` usage is thrown Relates to #334 --- packages/casl-ability/src/PureAbility.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/casl-ability/src/PureAbility.ts b/packages/casl-ability/src/PureAbility.ts index 60f4a8615..a9c8a7305 100755 --- a/packages/casl-ability/src/PureAbility.ts +++ b/packages/casl-ability/src/PureAbility.ts @@ -197,12 +197,12 @@ export class PureAbility const [action, subject, field] = args; const rules: Rule[] = (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));