AbilityBuilder fails when the ability factory is an arrow function with the error
TypeError: Cannot read properties of undefined (reading 'possibleRulesFor')
at isAbilityClass (node_modules/@casl/ability/src/AbilityBuilder.ts:87:8)
at AbilityBuilder.build (node_modules/@casl/ability/src/AbilityBuilder.ts:124:5)
This is because arrow functions don't have a .prototype property, and so isAbilityClass fails.
function isAbilityClass(factory: AbilityFactory<any>): factory is AnyClass {
return typeof factory.prototype.possibleRulesFor === 'function';
// ^ does not exist on arrow functions!
}
Describe the bug
AbilityBuilder
fails when the ability factory is an arrow function with the errorThis is because arrow functions don't have a
.prototype
property, and soisAbilityClass
fails.To Reproduce Steps to reproduce the behavior:
Expected behavior
AbilityBuilder
should work with arrow functions as the factory.Interactive example (optional, but highly desirable) N/A
CASL Version
@casl/ability
- v6.7.1@casl/mongoose
- v8.0.2Environment:
NodeJS v20.13.1