You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using Can in React (via createContextualCan), most of the type definitions strip (via Extract) most subject types, which prevents using ForcedSubject.
a. Intentional, and I'm doing something wrong by working around these types by using the only argument form (do/on) that doesn't Extract types, in which case
Please let me know so I don't cause issues in my project (and potentially the docs should be updated for createContextualCan() and/or subject())
Maybe the do/on arguments should also be updated to not allow ForcedSubject
or:
b. Unintentional and subject() should be usable with a/an/this, in which case, can Can.ts be updated to allow forced subjects?
CodeSandbox only warns about the TypeScript error (please hover over the last a statement), but my actual project fully crashes and rejects the error, causing even more dramatic and blocking issues.
Additional Note/Other Cases
As mentioned above, the do/on arguments do not use Extract<>, so it seems like I could write my code using them, but as the documentation says, they're not as elegant: "use do and on if you are bored and don't want to make your code more readable ;)"
The text was updated successfully, but these errors were encountered:
Basically when you use forced subject you need to use this property (i.e., Can I read this article? -> means can I read this particular article object). When you check permission on type, you need to use a or an property (i.e., Can I read an article? -> means at least one article)
Describe the bug
When using
Can
in React (viacreateContextualCan
), most of the type definitions strip (viaExtract
) most subject types, which prevents usingForcedSubject
.Please see lines of
Can.ts
:casl/packages/casl-react/src/Can.ts
Lines 18 to 21 in 94eec62
Is this:
a. Intentional, and I'm doing something wrong by working around these types by using the only argument form (
do
/on
) that doesn'tExtract
types, in which casecreateContextualCan()
and/orsubject()
)do
/on
arguments should also be updated to not allowForcedSubject
or:
b. Unintentional and
subject()
should be usable witha
/an
/this
, in which case, canCan.ts
be updated to allow forced subjects?To Reproduce
Reproduction in CodeSandbox, described below: https://codesandbox.io/p/sandbox/casl-can-replication-53tx88
Steps to reproduce the behavior:
Ability
types, based on the TypeScript guide - I've also defined a variant withForcedSubject
to allow typingCan
viacreateContextualCan
based on the React guide, specifying theActions
andSubjects
defined in (1)subject()
:<Can I="create" a={subject("Car", { make: "Ford", model: "Transit" })}>{/* ... */}</Can>
Expected behavior
No TypeScript errors when using ForcedSubjects with
<Can I="" a={subject()} />
Interactive example (optional, but highly desirable)
https://codesandbox.io/p/sandbox/casl-can-replication-53tx88
CodeSandbox only warns about the TypeScript error (please hover over the last
a
statement), but my actual project fully crashes and rejects the error, causing even more dramatic and blocking issues.Additional Note/Other Cases
As mentioned above, the
do
/on
arguments do not useExtract<>
, so it seems like I could write my code using them, but as the documentation says, they're not as elegant: "use do and on if you are bored and don't want to make your code more readable ;)"The text was updated successfully, but these errors were encountered: