-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing type-checking in classes with protected constructor #995
Comments
This is actually how types work in TS. You can read this answer on SO -> https://stackoverflow.com/questions/66599065/typescript-abstract-static-factory-with-protected-constructor#answer-70118566 The issue is that there is no other way to check that Function is actually a class -> https://www.typescriptlang.org/play/?#code/MYGwhgzhAEAqCmEAu0DeBYAUNaAHATgPZLzAkAm0whAdsvgK5mH4AU+8Y5tIAntAEtyALmj0BNAOYBKNAF8sCzFiS9c8OGo0BeaDXgB3aKwB0ZsPkkRRYGrwDaAXVnaAfNFv8VWzeoAi8ABm0Lqm5pbWHnZOLu6e0ABkaHhESMRaNnbQSt7qvvAAkhAAcsQAggDC4FAh0KrqhMEIyNDwAB4kNOQwsD4A-HWMGqKBYCAQ8LkaAEIMSAVIABKQAAqp6eoA8jQLtfXwjXCIKO2d3ckExBvw I obviously can check that object has So, this is not something what I plan to address immediately. You can just remove |
Hi @serhiistotskyi, thanks for your reply.
Unfortunately, the editor linked is empty. However, I found a solution that can be handy if someone else has the same need. Something like that:
In this way, it's possible to define conditions with the help of TypeScript: What's your opinion? Do you see any drawbacks? |
Describe the bug
Hello, I'm trying to set up CASL with NestJS and get full TypeScript support defining each ability (actions, subjects, fields, conditions) but something is missing.
My classes have the constructor protected, which CASL doesn't seem to like very much; however, I think I found an acceptable trade-off (if somewhat verbose).
This is what I've done so far:
Now, the action, the subject, and the fields are correctly checked, but for some reason, it can be done for the properties; as we can see there is no type-checking:
Is CASL doing something wrong or is it me?
CASL Version
@casl/ability: 6.7.2
Environment:
TypeScript: 5.6.3
NodeJS: 22
The text was updated successfully, but these errors were encountered: