Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

Re: #15718

Summary

Array of unions currently throws an error:

/home/v/Desktop/MongoDB/mongoose/lib/schema/union.js:23
    this.schemaTypes = options.of.map(obj => options.parentSchema.interpretAsType(key, obj, schemaOptions));
                                                                  ^

TypeError: Cannot read properties of undefined (reading 'interpretAsType')
    at /home/v/Desktop/MongoDB/mongoose/lib/schema/union.js:23:67
    at Array.map (<anonymous>)
    at new Union (/home/v/Desktop/MongoDB/mongoose/lib/schema/union.js:23:35)
    at new SchemaArray (/home/v/Desktop/MongoDB/mongoose/lib/schema/array.js:95:21)

This would have been fixed separately by the refactor in #15700

Examples

@vkarpov15 vkarpov15 added this to the 8.19.4 milestone Nov 4, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes support for arrays of union types (gh-15718). Previously, defining unions inside arrays would fail because the parentSchema property wasn't being set correctly for union types within arrays.

  • Sets parentSchema on union type definitions when they appear inside arrays
  • Adds test coverage for arrays of unions with mixed types (Number and Date)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/schema.js Sets parentSchema property on union types within array definitions
test/schema.union.test.js Adds test case verifying that arrays of unions work correctly with different value types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@timheerwagen timheerwagen mentioned this pull request Nov 4, 2025
2 tasks
@vkarpov15 vkarpov15 merged commit 5e95252 into master Nov 7, 2025
73 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-15718 branch November 7, 2025 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants