Skip to content
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

Export AddRule type from AbilityBuilder #911

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ludwigbacklund
Copy link

When using "moduleResolution": "Bundler" in tsconfig.json for a TypeScript project, and implicitly referencing AddRule you get this error:

The inferred type of '<my-own-function>' cannot be named without a reference to '../../../node_modules/@casl/ability/dist/types/types'. This is likely not portable. A type annotation is necessary.ts(2742)

These errors can be resolved by explicitly exporting these implicitly referenced types from @casl/ability, like in this PR.

My use case is something like this:

type Can = AbilityBuilder<UserAbility>['can'];
type Cannot = AbilityBuilder<UserAbility>['cannot'];

Where I then use these two types so that I can pass around can's and cannot's from my built ability into different functions.

Thanks!

@ludwigbacklund
Copy link
Author

@stalniy WDYT? :)

@stalniy
Copy link
Owner

stalniy commented May 20, 2024

Is the resulting type you get keeps all generic types and overloading of corresponding AbilityBuilder functions?

what I can tell about AbilityBuilder types is that they are super complicated and uses advanced type system features and HKT hacks in order to produce desired outcome. So, I’d not like to spread this type because very likely it may be broken with the next release (at least I can’t guarantee backward compatibility in this case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants