Skip to content

Conversation

@maynkxx
Copy link

@maynkxx maynkxx commented Nov 23, 2025

Fixes #15780

Problem

When using Schema.static({...}) with TypeScript generics, TypeScript required
that all properties defined in TStaticMethods be present in the object passed
to schema.static(). This prevented users from adding statics one at a time.

Solution

Make the mapped type keys optional:
{ [F in keyof TStaticMethods]?: TStaticMethods[F] }

This aligns Schema.static() with the behavior of Schema.method() and allows
incremental addition of static methods.

Notes

  • This change affects only TypeScript definitions.
  • No runtime behavior is touched.
  • Low risk, minimal change.

@vkarpov15 vkarpov15 requested a review from Copilot November 25, 2025 15:20
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.

Copilot wasn't able to review any files in this pull request.


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

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

I don't like the direction of this PR. Our current thinking is that we want to err on the side of being more strict with our types, because it is fairly easy to work around cases like this using as.

In the case of statics, if you want to define them one at a time, you can just use the static(name, fn) signature.

@hasezoey @AbdelrahmanHafez WDYT?

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Nov 26, 2025
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.

From a pure code/type style standpoint, this looks good to me, maybe consider adding a types test though.

Otherwise, i dont really have a preference in this case and either would be fine for me.

@vkarpov15 vkarpov15 closed this Nov 26, 2025
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.

All methods required by TS when setting statics via Schema.static with object parameter

3 participants