-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.16.2
Node.js version
22.13.1
MongoDB server version
8.0.4
Typescript version (if applicable)
5.7.3
Description
Discriminator models only have the _id and __v properties associated with their typings. All type inferences from its schema definition or the schema definition of its parent are lost.
Steps to Reproduce
const ParentSchema = new Schema({
field1: {
type: String,
require: true,
},
field2: Number,
}, {
discriminatorKey: 'field1',
})
const ParentModel = mongoose.model('Parent', ParentSchema)
const ChildSchema = new Schema({
field3: String,
})
const ChildModel = ParentModel.discriminator('child', ChildSchema)Typescript shows the fields associated with ChildModel and any documents created via ChildModel are just _id and __v when they should include field1, field2, and field3.
Expected Behavior
Correct type inference should show that fields associated with ChildModel and any documents created via ChildModel should include field1, field2, and field3.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request