-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Casl/mongoose and official mongoose types #436
Comments
Do you |
Thank you for the quick answer! Yes, I do have |
It seems like the issue is connected to |
Strange. Maybe in the latest version of Let me check it with the latest version |
They added official ts support in 5.11 and in 5.10 you need to use thats why they are incompatible |
Ok thank you, but the official types included in |
This is a breaking change for casl/mongoose, so very likely I'll ship it with #404 together . Also, currently I'm on holidays, so it won't be fast. I think I'll have time to fix this in the next couple weeks. |
@p-fruck did you check if |
it didn't work for me since the types provided by |
I do not recommend to use official types as there are a bunch of TypeScript related issues introduced in mongoose@5.11.x:
That makes it impossible to have the same level of TS support in the package. So, suggested workaround is to use {
"scripts": {
"postinstall": "rm -f node_modules/mongoose/index.d.ts"
}
} There is nothing better I can do with this until official mongoose types are improved |
looks like that ts issues where fixed by mongoose and I can try to implement it one more time with official types |
I work around this by setting "compilerOptions": {
"skipLibCheck": true
}
} |
fixed in @casl/mongoose@5.0.0 |
Thank you! |
Hi everyone, I'm getting this error and reading the comments above didn't help. What am I doing wrong?
|
Same problem |
Looks like types on Query doesn't work properly |
Any update on this? |
Nothing new, I have one project were I have older mongoose version. As soon as I finish some refactoring and will be able to update to newer version I’ll check it. Very low on free time right now. Also, I fed up with mongoose types so very likely will create an alternative fully typesafe mongo db DAL lib based on json schema in the next year. |
I totally understand, do you have advice on how we can hide these type errors created by accessibleBy? |
We were able to get types working with the following setup! Posting here for others who are running into this issue. import { AnyMongoAbility, Generics, Normalize } from "@casl/ability";
import { DocumentQuery, Model, Types, Document } from "mongoose";
type Schema = { _id: Types.ObjectId };
type ExtractQueryHelpersFromDocument<D> = D extends Document<any, infer QueryHelpers, any>
? QueryHelpers
: never;
export type AccessibleBy<T extends Schema, D extends Document> = <U extends AnyMongoAbility>(
ability: U,
action?: Normalize<Generics<U>["abilities"]>[0]
) => DocumentQuery<T & D, D, ExtractQueryHelpersFromDocument<D>>;
export interface AccessibleRecordModel<
T extends Schema,
D extends Document,
QueryHelpers = {},
Methods = {}
> extends Model<
T,
QueryHelpers & {
accessibleBy: AccessibleBy<T, D>;
},
Methods
> {
accessibleBy: AccessibleBy<T, D>;
}` |
still the same issue with "mongoose": "~6.6.0" and "@types/mongoose": "^5.11.97" mean should downground the version in 2022 ??? |
You don’t need types/mongoose anymore. Mongoose provides built-in types |
@stalniy but not working without types/mongoose |
tests for casl/mongoose are written in ts and they work. If smth doesnt work for you, please make a minimal repo/example where I can take a look. |
Hey @stalniy, thank you for your awesome work on this project. I just got started using the casl library for permission management and I really love it so far, but there's one small issue I wasn't able to fix:
Describe the bug
I am using the
@casl/ability
and the@casl/mongoose
package to manage database permissions within nodejs. My code runs just fine but as soon as I want to compile my typescript project using tsc, it just errors out.To Reproduce
Steps to reproduce the behavior:
I've created
src/test.ts
within my current project with the following content:Expected behavior
Running
npx tsc src/test.ts
should just compile the ts file. Instead, I get the following error message:CASL Version
@casl/ability
- v 5.1.2@casl/mongoose
- v 3.2.2Environment:
Fedora 33, Node 14.15.1
mongoose
- v 5.11.11typescript
-v 4.1.3The text was updated successfully, but these errors were encountered: