Hi I'm creating CASL auth in my nest app. Unfortunately i have this error on Action.Update
can(Action.Update, selectTeamSchema, { createdById: user.id });
No overload matches this call.
Overload 1 of 2, '(action: never[], subject: never[], fields?: string | string[], conditions?: MongoQuery<never>): RuleBuilder<MongoAbility<PossibleAbilities, Conditions>>', gave the following error.
Argument of type 'import("/src/ability/ability.factory").Action' is not assignable to parameter of type 'never[]'.
Overload 2 of 2, '(action: never[], subject: never[], conditions?: MongoQuery<never>): RuleBuilder<MongoAbility<PossibleAbilities, Conditions>>', gave the following error.
Argument of type 'import("src/ability/ability.factory").Action' is not assignable to parameter of type 'never[]'.ts(2769)
(enum member) Action.Update = "update"
This is the code
type Subjects = InferSubjects<SelectUserType | SelectTeamType>;
type PossibleAbilities = [Action, Subjects];
export type Conditions = MongoQuery;
export type AppAbility = MongoAbility<PossibleAbilities, Conditions>;
export enum Action {
Manage = 'manage',
Create = 'create',
Read = 'read',
Update = 'update',
Delete = 'delete',
}
@Injectable()
export class AbilityFactory {
userInTeamAbility(user: SelectUserType) {
const { can, cannot, build } = new AbilityBuilder(
createMongoAbility<PossibleAbilities, Conditions>,
);
can(Action.Update, selectTeamSchema, { createdById: user.id });
return build({
detectSubjectType: (item) =>
item.constructor as ExtractSubjectType<Subjects>,
});
}
}
The selectTeamSchema or SelectUserType are just zod objects. Any one know why I'm getting this error?
Try to do this: