question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<Can> without subject

See original GitHub issue

I have a flat component permission-wise, I do not really use the “of” -part (or subject) of the <Can> component. Casl seems to work fine with me leaving it out but the React component gives prop type warnings. I have worked around this by creating a custom can-component but I’m wondering if the prop-type validation could be loosened or if there is a more elegant way handling cases like: <Can I="post" />

Tasks:

  • update types for ForbiddenError.throwUnlessCan
  • update types for can, cannot, relevantRuleFor, rulesFor, possibleRulesForofAbility`
  • update types for can & cannot of AbilityBuilder
  • casl/angular
  • casl/aurelia
  • casl/vue
  • casl/react
  • add tests for casl/ability

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
stalniycommented, Feb 20, 2020

will be available in casl 4.x

1reaction
stalniycommented, Jul 3, 2019

After some thinking about this, I realised that on @casl/ability level it can be implemented without changes. The only thing which you need to do is to define custom subjectName function:

const subjectName = () => 'all'

const ability = AbilityBuilder.define({ subjectName }, (can) => {
  can('read')
  can('think')
})

console.log(ability.can('think')) // true
console.log(ability.can('write')) // false

The only thing which needs to be changed is Typescript declarations and complementary packages

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it correct to use 'can' in a sentence without a subject, like ...
So, no: It's not correct to use “can” in a sentence without a subject.
Read more >
Verb "to be" without a subject not allowed?
A reviewer said this sentence is not correct, because the verb "to be" cannot be used without a subject. It should be: The...
Read more >
Definition and Examples of Null Subjects in English - ThoughtCo
A null subject is the absence (or apparent absence) of a subject in a sentence. In most cases, such truncated sentences have an...
Read more >
Null-subject language - Wikipedia
"[(S)he] does not want to pay." The subject "(s)he" of the second sentence is only implied in Italian. English and French, on the...
Read more >
Verbs without subject | WordReference Forums
They are different tenses. The imperative tense ("verbs without subject") is used to express orders or commands and it is not the present...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found