Repository navigation
Replies: 1 comment
|
just don't use type Models = { User: User; Post: Post }
type ModelsWithTypename = { [K in keyof Models]: Models[K] & { __typename: K } } // <--- use this instead of Subjects |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'm working on setting up authorization in my TypeScript application using CASLand Prisma. In my setup, I use the
detectSubjectTypefunction to specify how to detect the subject type, and I expect each item to have the__typenamefield.Here's the relevant part of my ability setup:
I also have an
asfunction that adds the__typenamefield to a subject:When I check permissions using the ability, I use the
asfunction to ensure the subject has the__typenamefield:However, I'm running into a TypeScript error when using
ability.can:It seems that CASL's
ForcedSubjecttype expects the subject to have a__caslSubjectType__property. But in my setup, I want to use__typenameinstead.My Question:
__typenamefor the subject type instead of__caslSubjectType__?__typenameas the subject type identifier?Additional Information:
I understand that
ForcedSubjectis a type used internally by CASL to enforce the presence of the__caslSubjectType__property for type checking. However, since I'm already using__typenamein mydetectSubjectTypefunction, I'd like to avoid adding another property to my subjects if possible.What I've Tried:
Attempted to adjust my types to include
__caslSubjectType__, but this feels redundant since__typenameis already serving that purpose in my setup.Any help or guidance would be greatly appreciated!
Note: I'm using the following versions:
Thank you!
All reactions