Skip to content

Instantly share code, notes, and snippets.

@stalniy
Created April 10, 2020 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stalniy/9845d3a64982a111057b267455be5a8d to your computer and use it in GitHub Desktop.
Save stalniy/9845d3a64982a111057b267455be5a8d to your computer and use it in GitHub Desktop.
CASL 4.0 subject type detection for POJO
import { defineAbility, subject as an } from '@casl/ability';
const object = {
title: 'My article',
description: '...',
};
ability.can('read', an('Article', object));
// or
const article = an.bind(null, 'Article');
ability.can('read', article(object));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment