error on new Ability(rules)
See original GitHub issueHi, 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:
- Created 3 years ago
- Comments:16 (9 by maintainers)
Top GitHub Comments
Starting from 4.0,
AbilityBuilder
accepts optional generic parameterTAbility
, by default this parameter equalsPureAbility
. What you need to do is to change how you createAbilityBuilder
:For more details check the API docs
@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