Skip to content

types: automatically infer discriminator type #15547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 25, 2025
Merged

Conversation

vkarpov15
Copy link
Collaborator

Fix #15535

Summary

Add a discriminator() function override that automatically infers the returned schema type from TypeScript types by combining the schema generics.

Examples

@vkarpov15 vkarpov15 added this to the 8.17 milestone Jul 22, 2025
Copilot

This comment was marked as outdated.

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Jul 23, 2025
@vkarpov15 vkarpov15 requested review from hasezoey and Copilot July 23, 2025 15:38
Copy link
Contributor

@Copilot 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 issue #15535 by implementing automatic type inference for discriminator schemas. The main purpose is to enhance TypeScript support by allowing the discriminator function to automatically combine schema generics and return the properly typed discriminator model.

  • Adds a new test case demonstrating proper type inference for discriminator models with parent and child schemas
  • Updates TypeScript instantiation limits to accommodate the enhanced type checking complexity
  • Upgrades TypeScript version in benchmarks to support the new type inference features

Reviewed Changes

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

File Description
test/types/discriminator.test.ts Adds comprehensive test case for automatic discriminator type inference using expectType assertions
scripts/tsc-diagnostics-check.js Increases maximum TypeScript instantiation limit from 275,000 to 280,000
benchmarks/typescript/simple/package.json Updates TypeScript dependency from 5.5.x to 5.8.x
Comments suppressed due to low confidence (1)

@vkarpov15
Copy link
Collaborator Author

@hasezoey can you take another look? I did some performance refactoring to reduce and offset the additional instantiations introduced by this PR.

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

Still looks good to me.

@vkarpov15 vkarpov15 changed the base branch from master to 8.17 July 24, 2025 13:52
@vkarpov15 vkarpov15 merged commit 633a50c into 8.17 Jul 25, 2025
5 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-15535-2 branch July 25, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type inference for discriminator models are broken
2 participants