Skip to content

types: handle compiling with exactOptionalPropertyTypes#16277

Merged
vkarpov15 merged 1 commit intomasterfrom
vkarpov15/gh-16273
May 8, 2026
Merged

types: handle compiling with exactOptionalPropertyTypes#16277
vkarpov15 merged 1 commit intomasterfrom
vkarpov15/gh-16273

Conversation

@vkarpov15
Copy link
Copy Markdown
Collaborator

Fix #16273

Summary

Fix compiling with TypeScript's exactOptionalPropertyTypes flag. I also added a separate test folder with a separate tsconfig.json for testing compiling with that flag set.

Examples

Copy link
Copy Markdown
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

Updates Mongoose’s published TypeScript declaration files to compile cleanly when consumers enable exactOptionalPropertyTypes (and skipLibCheck: false), and adds a dedicated type-test setup to continuously validate that configuration.

Changes:

  • Fix TS2344 errors under exactOptionalPropertyTypes by excluding undefined from Options['enum'] when threading enum options through recursive path-type resolution.
  • Add a new test/types/exactOptionalPropertyTypes folder with its own tsconfig.json that enables exactOptionalPropertyTypes + skipLibCheck: false.
  • Expand tstyche’s test glob to include nested test/types/** type tests.

Reviewed changes

Copilot reviewed 3 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
types/inferschematype.d.ts Removes undefined from Options['enum'] in recursive ResolvePathType calls to satisfy SchemaTypeOptions constraints under exact optional semantics.
types/inferrawdoctype.d.ts Same enum/undefined exclusion fix for ResolveRawPathType recursion.
types/inferhydrateddoctype.d.ts Same enum/undefined exclusion fix for hydrated doc path inference recursion.
tstyche.json Updates test file matching to include nested test/types/**/*.test.* files.
test/types/exactOptionalPropertyTypes/tsconfig.json Adds a stricter TS config for this sub-suite (exactOptionalPropertyTypes: true, skipLibCheck: false).
test/types/exactOptionalPropertyTypes/exactOptionalPropertyTypes.test.ts Adds a type test to ensure Mongoose’s .d.ts files type-check under the stricter config.

@mrazauskas
Copy link
Copy Markdown
Contributor

It is more involving, but perhaps it is worth setting "exactOptionalPropertyTypes": true directly in test/types/tsconfig.json for all type tests? Code that compiles when "exactOptionalPropertyTypes" is enabled, would also compile when it is disabled.

I can do this next week (after my vacation).

@vkarpov15
Copy link
Copy Markdown
Collaborator Author

That seems reasonable. I'll merge this for now to unblock people.

@vkarpov15 vkarpov15 merged commit ccac981 into master May 8, 2026
9 checks passed
@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label May 9, 2026
@hasezoey hasezoey deleted the vkarpov15/gh-16273 branch May 9, 2026 09:36
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.

types: TS2344 error in inferschematype.d.ts and inferrawdoctype.d.ts with exactOptionalPropertyTypes: true and skipLibCheck: false

4 participants