question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error on new Ability(rules)

See original GitHub issue

Hi, I’m using casl angular and have alredy update the version from 3.X to 4. I have updated my code a little but doesn’t work.

Current version: “@casl/ability”: “^4.0.8”, “@casl/angular”: “^4.0.4”,

private defineAbilityFor(user: Employee) {
    const { can, cannot, rules } = new AbilityBuilder();
    if (user.isAdmin) {
      can('manage', 'all');
    } else if (user.isUser) {
      can('read', 'all');
      for (const projectData of user.MandatoryProjectList) {
        can(['share', 'edit', 'assign'], 'Project', { idProject: projectData.idProject });
      }
      cannot(['edit', 'delete'], Company);
    }

    // return rules;
    return new Ability(rules);
  }

Returns a error on the line return new Ability(rules);

ERROR in src/app/services/auth.service.ts:86:24 - error TS2345: Argument of type ‘(ClaimRawRule<string> | LegacyClaimRawRule<string> | SubjectRawRule<string, SubjectType, unknown> | LegacySubjectRawRule<string, SubjectType, unknown>)[]’ is not assignable to parameter of type ‘(SubjectRawRule<string, SubjectType, unknown> | LegacySubjectRawRule<string, SubjectType, unknown>)[]’. Type ‘ClaimRawRule<string> | LegacyClaimRawRule<string> | SubjectRawRule<string, SubjectType, unknown> | LegacySubjectRawRule<string, SubjectType, unknown>’ is not assignable to type ‘SubjectRawRule<string, SubjectType, unknown> | LegacySubjectRawRule<string, SubjectType, unknown>’. Type ‘ClaimRawRule<string>’ is not assignable to type ‘SubjectRawRule<string, SubjectType, unknown> | LegacySubjectRawRule<string, SubjectType, unknown>’. Type ‘ClaimRawRule<string>’ is not assignable to type ‘SubjectRawRule<string, SubjectType, unknown>’. Property ‘subject’ is optional in type ‘ClaimRawRule<string>’ but required in type ‘SubjectRawRule<string, SubjectType, unknown>’.

86 return new Ability(rules);


Angular CLI: 9.1.4 Node: 10.15.3 OS: darwin x64

Angular: 9.1.4 … animations, cli, common, compiler, compiler-cli, core, forms … language-service, platform-browser, platform-browser-dynamic … router Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.900.7 @angular-devkit/build-angular 0.900.7 @angular-devkit/build-optimizer 0.900.7 @angular-devkit/build-webpack 0.900.7 @angular-devkit/core 9.0.7 @angular-devkit/schematics 9.1.4 @angular/cdk 9.2.2 @angular/flex-layout 9.0.0-beta.29 @angular/material 9.2.2 @angular/material-moment-adapter 9.2.2 @ngtools/webpack 9.0.7 @schematics/angular 9.1.4 @schematics/update 0.901.4 rxjs 6.5.5 typescript 3.7.5 webpack 4.41.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
stalniycommented, May 6, 2020

Starting from 4.0, AbilityBuilder accepts optional generic parameter TAbility, by default this parameter equals PureAbility. What you need to do is to change how you create AbilityBuilder:

const { can, cannot, rules } = new AbilityBuilder<Ability>();

For more details check the API docs

0reactions
theGCcommented, Nov 10, 2020

@stalniy that’s got it, thank you and thanks for all your hard work on CASL. Been using it within Feathers for a few days now and it’s making things much clearer in their structure and logic. Looking forward to v5 👍

In case it helps anyone else, I’ve updated the sandbox and pulled it more in line with the cookbook article:

https://codesandbox.io/s/casl-demo-roles-with-static-permissions-02kls?file=/src/index.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error | Slap Battles Wiki - Fandom
Error's ability is called Death, (unofficial name) upon being activated the player will instantly die and error noises will play alongside the death....
Read more >
Error handling with abilities · Unison programming language
In this doc we'll go through some common patterns and examples for expressing and handling errors with abilities in Unison.
Read more >
Rule 103. Rulings on Evidence | LII / Legal Information Institute
(a) Preserving a Claim of Error. A party may claim error in a ruling to admit or exclude evidence only if the error...
Read more >
MotM's new ability score bonuses have me confused. Can ...
I've been hearing that, apparently, a new rule for racial ability score bonuses has come with Monsters of the Multiverse.
Read more >
COMMON ERRORS IN KRONOS AND HOW TO FIX THEM
Employee Error Details. Entering work hours before they have actually been worked. Employees are not allowed to record their work time until they...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found