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
The MergeUnion<T> type in @casl/ability is overly restrictive, causing TypeScript errors when using dot-notation paths (e.g., 'tenant.id') in conditions. This limitation prevents referencing nested properties as string keys, even though CASL and MongoDB support such syntax.
Steps to Reproduce
Configure an ability:
import{AbilityBuilder,Ability}from'@casl/ability';const{ can, build }=newAbilityBuilder(Ability);can('read','User',{'tenant.id': '12345'});// Dot-notation for nested propertyconstability=build();
Check permissions:
ability.can('read','User',userData);
TypeScript raises an error:
TS2345: Argument of type `{ 'tenant.id': string }` is not assignable...
Expected Behavior
TypeScript should allow dot-notation paths without requiring type casting.
Proposed Fix
Modify MergeUnion<T> in conditions.ts to support arbitrary string keys:
This change will basically allow any stringed property to be specified in conditions. Which is not good for the case when there are properly configured types.
I’ll double check this but I had the impression that TS will infer it by default from this mapping type
Bug Description
The
MergeUnion<T>
type in@casl/ability
is overly restrictive, causing TypeScript errors when using dot-notation paths (e.g.,'tenant.id'
) in conditions. This limitation prevents referencing nested properties as string keys, even though CASL and MongoDB support such syntax.Steps to Reproduce
Expected Behavior
TypeScript should allow dot-notation paths without requiring type casting.
Proposed Fix
Modify
MergeUnion<T>
in conditions.ts to support arbitrary string keys:This change aligns TypeScript behavior with CASL’s runtime capabilities, improving developer experience while maintaining backward compatibility.
Environment
@casl/ability
: v6.7.4The text was updated successfully, but these errors were encountered: