Skip to content

types: improve typing for transform option to toJSON and toObject #15485

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vkarpov15
Copy link
Collaborator

Fix #15479

Summary

Better typing for the transform() function, 2nd arg should be a raw doc type by default not Record<string, any>.

Maybe worthwhile to postpone this for a minor release, WDYT @hasezoey ?

Examples

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

Adds a type-level test to verify that the transform callback on toJSON receives the correct raw document type and enforces proper return typing.

  • Introduces a new test function gh15479 to cover transform option typing
  • Defines a transform callback with doc and ret parameters and uses toJSON generics
  • Verifies that the returned object omits testField when using the transformed return type
Comments suppressed due to low confidence (1)

test/types/schema.test.ts:1816

  • [nitpick] The test function name gh15479 is not descriptive. Consider renaming it to something like testTransformOptionTyping or using Jest's test/it syntax with a descriptive title.
function gh15479() {

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.

LGTM, works with typegoose in its current state. Though because it modifies something likely used, i would agree to postpone it to a minor release.

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

Can't get typing for output of toJSON
2 participants