stalniy / casl

CASL is an isomorphic authorization JavaScript library which restricts what resources a given user is allowed to access
https://casl.js.org/
MIT License
5.93k stars 269 forks source link

AbilityBuilder in ts - expected 1 arguments but got 0 #453

Closed jeremygottfried closed 3 years ago

jeremygottfried commented 3 years ago

Describe the bug When using typescript and following the docs, I get two errors:

  1. On new AbilityBuilder(), the error is expected 1 arguments but got 0.
  2. On new Ability(rules), the error is Screen Shot 2021-01-28 at 4 58 13 PM To Reproduce
    
    import { AbilityBuilder, Ability } from '@casl/ability';

export default function defineAbilitiesFor() { const { can, rules } = new AbilityBuilder();

return new Ability(rules); };



**Expected behavior**
For the simplest example from the docs to work

**CASL Version**

<!-- leave packages which you use -->

`@casl/ability` - v 5.2.2

**Environment**:
<!-- Nodejs version or Browser version or TypeScript version -->
Node 12.16.3
Typescript 4.1.3
ts-node 9.1.1
MacOS Catalina 10.15.1
jeremygottfried commented 3 years ago

This seems to be a documentation issue. https://github.com/stalniy/casl#1-define-abilities

The example there doesn't have Ability as an argument to AbilityBuilder

I will submit a PR to correct it

stalniy commented 3 years ago

Thank you!

stalniy commented 3 years ago

Yes, starting from v5 AbilityBuilder requires a parameter. Just to make sure people understand which Ability class is going to build.