Search code examples
typescriptcasl

CASL & Typescript basic RBAC set up


I've been testing CASL for a new project and was after some help getting a basic typescript RBAC set up configured on CodeSandbox:

https://codesandbox.io/s/wonderful-meadow-02kls?file=/src/index.ts

I've pulled pieces from the cookbook at:

https://casl.js.org/v4/en/cookbook/roles-with-static-permissions

I've hit a number of errors and am not well enough versed in Typescript to understand where things are tripping up.

Any help would be much appreciated.


Solution

  • There is some issue with interpretation of typeof operator in codesandbox. If you change that to regular types:

    type AppAbilities = [
      'update',
      'User' | 'all'
    ]
    

    Everything works as expected. Update sample: https://codesandbox.io/s/eloquent-jang-0jl6s?file=/src/index.ts