francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
105 stars 25 forks source link

Creates types incompatible with typescript 3.x #60

Closed Narretz closed 3 years ago

Narretz commented 3 years ago

See this repo: https://github.com/Narretz/mongoose-tsgen-issues/tree/typescript (make sure to check out the typescript branch)

I don't think it's documented explicitly which typescript versions are supported, but the package.json itself requires ^3.9.7. However, if your own code is requiring typescript 3.9.7, it won't work, because te generated type will throw a bunch of errors:

src/interfaces/mongoose.gen.ts:268:35 - error TS2344: Type 'Unarray<ResultType>' does not satisfy the constraint 'Document<any, any>'.
  Type '{}' is missing the following properties from type 'Document<any, any>': $getAllSubdocs, $ignore, $isDefault, $isDeleted, and 48 more.

268         ? Array<PopulatedDocument<Unarray<ResultType>, T>>
                                      ~~~~~~~~~~~~~~~~~~~

src/interfaces/mongoose.gen.ts:270:29 - error TS2344: Type 'Unarray<ResultType>' does not satisfy the constraint 'Document<any, any>'.
  Type 'unknown' is not assignable to type 'Document<any, any>'.

270         ? PopulatedDocument<Unarray<ResultType>, T>
                                ~~~~~~~~~~~~~~~~~~~

src/interfaces/mongoose.gen.ts:281:35 - error TS2344: Type 'Unarray<ResultType>' does not satisfy the constraint 'Document<any, any>'.

281         ? Array<PopulatedDocument<Unarray<ResultType>, T>>
                                      ~~~~~~~~~~~~~~~~~~~

src/interfaces/mongoose.gen.ts:283:29 - error TS2344: Type 'Unarray<ResultType>' does not satisfy the constraint 'Document<any, any>'.

283         ? PopulatedDocument<Unarray<ResultType>, T>
                                ~~~~~~~~~~~~~~~~~~~
francescov1 commented 3 years ago

Good catch, I'll look into this fix over the weekend! For the time being, you should be able to pass the --no-populate-overload flag to avoid augmenting populations (if those errors above are the only issue). Will get back to you soon!

Narretz commented 3 years ago

Thanks! These errors are the only ones, so the option should fix it as a workaround.

francescov1 commented 3 years ago

Fixed in 8.3.5! Added Typescript as a peer dependency.