@casl/vue: wrong 'do' prop check in can.ts
See original GitHub issueDescribe the bug
Cannot use I
prop in Can
component
To Reproduce
<Can I="read" a="Post"></Can>
It’s an example from docs
Expected behavior
Can
component should use I
or do
prop.
if I
is undefined then use do
prop
or if do
is undefined
then use I
prop.
Let’s see can.ts Line 66
const $props = props as Record<string, any>;
let actionProp = 'do';
let subjectProp = 'on';
if (!(actionProp in props)) {
actionProp = 'I';
subjectProp = detectSubjectProp(props);
}
I checked props
parameter in debugger.
Even if when I use I
property but props has a key of do
with undefined
value.
I think that condition should be like below
if ($props[actionProp] === undefined) {
actionProp = 'I';
subjectProp = detectSubjectProp(props);
}
and also detectSubjectProp
too
function detectSubjectProp(props: Record<string, unknown>) {
if (props['a'] !== undefined) {
return 'a';
}
if (props['this'] !== undefined) {
return 'this';
}
if (props['an'] !== undefined) {
return 'an';
}
return '';
}
It works for me !
CASL Version
@casl/ability
- v6.3.1
@casl/vue
- v2.2.0
Environment:
Node: v16.17.0
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Vue error on casl + vue when registering Can component ...
ts (112, 3): The last overload is declared here. My package.json contains: "dependencies": { "@casl/ability": "^4.0 ...
Read more ><Can> without subject · Issue #107 · stalniy/casl - GitHub
Casl seems to work fine with me leaving it out but the React component gives prop type warnings. ... Tasks: update types for...
Read more >CASL Vue
Let's consider PROS and CONS of both solutions in order to make the decision. Can Component: PROS: declarative; can cache permissions check results...
Read more >stalniy-casl/casl - Gitter
I'm evaluating CASL for a FeathersJS/Sequelize/Postgres app. I'm trying to figure out how I would express rules for objects deep in the object...
Read more >Vue error on casl + vue when registering Can component ...
Coding example for the question Vue error on casl + vue when registering Can component globally-Vue.js.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You used
in
operator to checkactionProp
isdo
orI
. Vue initializes component propertydo
withundefined
even if I usedI
property withoutdo
.For example
Properties
so…
actionProp
is stilldo
andprops
has a key ofdo
and!(actionProp in props)
equalsfalse
and$props[actionProp]
isundefined
then “NeitherI
nordo
prop was passed in <Can>” error will be thrown.I don’t understand why that test passed. I’m using
nuxt3-rc.12
and actually not working.looks like from vue@3.1.x or vue@3.2.x the behavior was changed because it worked as expected in vue@3.0.x