Skip to content

types(schema): treat Int32 paths as number - #16565

Merged
vkarpov15 merged 2 commits into
Automattic:masterfrom
lazerg:fix/issue-16564-int32-number-type
Oct 7, 2026
Merged

vkarpov15 merged 2 commits into
Automattic:masterfrom
lazerg:fix/issue-16564-int32-number-type

Conversation

@lazerg

@lazerg lazerg commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix #16564

Schema.Types.Int32 casts to a plain JS number at runtime, but NumberSchemaDefinition didn't include it. So a Schema<{ priority: number }> rejected type: Schema.Types.Int32, and inference fell through to the typeof SchemaType branch and typed the path as a Schema.Types.Int32 instance. This adds Schema.Types.Int32 (and the 'int32'/'Int32' strings, which mongoose also accepts) to NumberSchemaDefinition, so those paths are typed as number everywhere number paths are.

Examples

const schema = new Schema({ priority: { type: Schema.Types.Int32, required: true } });
const doc = new (model('Test', schema))({ priority: 1 });
const priority: number = doc.priority; // was TS2322, now compiles

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟒 Approval recommended

The implementation is correct, with only minor missing coverage for the lowercase alias.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Updates Int32 schema definitions so TypeScript consistently treats Int32 paths as JavaScript numbers.

Changes:

  • Adds Int32 constructors, instances, and string aliases to NumberSchemaDefinition.
  • Adds compile-time coverage for typed, inferred, lean, and raw documents.
File Description
types/​index.d.ts Classifies Int32 schema definitions as numeric.
test/​types/​schema.test.ts Verifies Int32 type inference.

πŸ’‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/types/schema.test.ts Resolved

@vkarpov15 vkarpov15 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks πŸ‘

@vkarpov15 vkarpov15 added this to the 9.11.1 milestone Oct 7, 2026
@vkarpov15
vkarpov15 merged commit 0e30afa into Automattic:master Oct 7, 2026
6 checks passed
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.

TypeScript: Schema.Types.Int32 is rejected for number fields and incorrectly inferred

3 participants