Casl/mongoose and official mongoose types
See original GitHub issueHey @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:
import { accessibleRecordsPlugin } from '@casl/mongoose';
import * as mongoose from 'mongoose';
mongoose.plugin(accessibleRecordsPlugin);
Expected behavior
Running npx tsc src/test.ts
should just compile the ts file. Instead, I get the following error message:
npx tsc src/test.ts
node_modules/@casl/mongoose/dist/types/accessible_records.d.ts:3:18 - error TS2305: Module '"mongoose"' has no exported member 'DocumentQuery'.
3 import { Schema, DocumentQuery, Model, Document } from 'mongoose';
~~~~~~~~~~~~~
node_modules/@casl/mongoose/dist/types/accessible_records.d.ts:6:76 - error TS2314: Generic type 'Model<T>' requires 1 type argument(s).
6 export interface AccessibleRecordModel<T extends Document, K = {}> extends Model<T, K & {
~~~~~~~~~~~~~~
7 accessibleBy: GetAccessibleRecords<T>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 }> {
CASL Version
@casl/ability
- v 5.1.2
@casl/mongoose
- v 3.2.2
Environment:
Fedora 33, Node 14.15.1
mongoose
- v 5.11.11
typescript
-v 4.1.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:25 (13 by maintainers)
Top GitHub Comments
fixed in @casl/mongoose@5.0.0
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
@types/mongoose
and remove official types throughpostinstall
npm hook:There is nothing better I can do with this until official mongoose types are improved