Skip to content
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

Fix typings for snapshot processor #2198

Merged

Conversation

thegedge
Copy link
Collaborator

@thegedge thegedge commented Jul 14, 2024

What does this PR do and why?

Previously, we weren't properly pulling out the input/output snapshot types of the referenced type in snapshot processors, forcing explicit generic argument specification or typing on the processor functions to avoid _NotCustomized:

CleanShot 2024-07-14 at 13 33 08@2x

This PR fixes that issue by choosing the given types input/output snapshot if the snapshot processor isn't customized.

Two other small additions in here:

  1. bun.lockb appeared to be out of date, so I added the updates
  2. Fixed some docs that had xyzProcess instead of xyzProcessor

Steps to validate locally

Tests added to validate.

@coolsoftwaretyler
Copy link
Collaborator

Will take a look this week!

Copy link
Collaborator

@coolsoftwaretyler coolsoftwaretyler left a comment

Choose a reason for hiding this comment

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

Hey @thegedge, three things:

  1. praise: thank you for fixing up the docs! That helps a lot.
  2. nitpick: I added the describe import from bun:test so we can use that with TS. I think that may actually be why you found you wanted @types/jest in Fix tsconfig and typechecking #2200. We no longer use Jest. bun:test is mostly a drop in replacement with its own types, but we do need to actually import from that namespace. I pushed that up.
  3. issue: I'm seeing a type error in the produces the right types when not customized test:
Screenshot 2024-07-21 at 2 37 43 PM

This goes away if instead we write either:

        assertTypesEqual(snapshot, _ as ModelCreationType<{ name: string | undefined }>)

Or

        assertTypesEqual(snapshot, _ as SnapshotIn<typeof Model>)

I'm partial to the second one since that's more accessible to users. But I wanted to check to see if you also see this issue or not, and if the SnapshotIn<> solution changes what we're actually asserting here.

Let me know what you think. Happy to merge this in once we are aligned on this TS error in the test file.

@thegedge
Copy link
Collaborator Author

thegedge commented Jul 25, 2024

I'm partial to the second one too!

And good to know about (2). Thanks for fixing <3

@coolsoftwaretyler
Copy link
Collaborator

Hey @thegedge - ready for another look on my end?

@thegedge
Copy link
Collaborator Author

Oh yeah, totally

@coolsoftwaretyler
Copy link
Collaborator

LGTM! I'm gonna merge this and target it as part of the v7 release because I think TS changes are a little nicer behind major versions, even though this is mostly fixing a problem rather than making a sweeping change.

@coolsoftwaretyler coolsoftwaretyler merged commit d5669e1 into mobxjs:master Jul 29, 2024
1 check passed
@thegedge thegedge deleted the fix-snapshot-processor-types branch July 29, 2024 15:55
@thegedge
Copy link
Collaborator Author

LGTM! I'm gonna merge this and target it as part of the v7 release because I think TS changes are a little nicer behind major versions, even though this is mostly fixing a problem rather than making a sweeping change.

I think that's fair, given this is a prerequisite for #2199, which is a far more significant typing change!

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.

2 participants