Incompatibility with Typescript 4.8.2 - Schemas that use query population (ObjectId and Ref) fail with serialization errors
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
6.5.4
Node.js version
14.17.6
MongoDB server version
4.2 but N/A
Description
When using a schema that uses query population and has a property defined with type
set to ObjectId and a ref
set. You get serialization errors when building. This seems to have started occurring recently, I tested with Typescript 4.8.2 but suspect its anything 4.8.x
src/person/schemas/person.schema.ts:23:14 - error TS4118: The type of this node cannot be serial ized because its property ‘[iterator]’ cannot be serialized. 23 export const PersonSchema = new Schema( ~~~~~~~~~~~~ src/person/schemas/person.schema.ts:23:14 - error TS4118: The type of this node cannot be serialized because its property ‘[species]’ cannot be serialized. 23 export const PersonSchema = new Schema( ~~~~~~~~~~~~ src/person/schemas/person.schema.ts:23:14 - error TS4118: The type of this node cannot be serialized because its property ‘[toStringTag]’ cannot be serialized. 23 export const PersonSchema = new Schema( ~~~~~~~~~~~~ src/person/schemas/person.schema.ts:23:14 - error TS4118: The type of this node cannot be serialized because its property ‘[iterator]’ cannot be serialized. 23 export const PersonSchema = new Schema( ~~~~~~~~~~~~ src/person/schemas/person.schema.ts:23:14 - error TS4118: The type of this node cannot be serialized because its property ‘[species]’ cannot be serialized. 23 export const PersonSchema = new Schema( ~~~~~~~~~~~~ src/person/schemas/person.schema.ts:23:14 - error TS4118: The type of this node cannot be serialized because its property ‘[toStringTag]’ cannot be serialized. 23 export const PersonSchema = new Schema( ~~~~~~~~~~~~ Found 6 error(s).
Steps to Reproduce
Using typescript version 4.8.2 have the following schema and try build:
export const PersonSchema = new Schema(
{
information: InformationSchema
})
export const InformationSchema = new Schema({
foo: { type: Schema.Types.ObjectId, ref: 'PersonModel' }
})
Expected Behavior
A successful build. Instead you get the errors mentioned above
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:8
Top GitHub Comments
@piercy Can you try with this fix that I’ve made? https://github.com/HiiiiD/mongoose/tree/fix-path-types
I can confirm this is an issue, and the issue is fixed by #12352. This will be fixed when we release 6.7.0.