Skip to content

Conversation

@cngonzalez
Copy link
Member

@cngonzalez cngonzalez commented Sep 16, 2025

Description

The template literal type for ValidProjection was a bit too strict, pretty much always resulting in error and user confusion. As far as I can tell there is no way to declare this type to be a bit more forgiving without making something kind of messy, so I've deprecated it and changed it to a string.

I've kept the type for backwards compatibility but redeclared it to a string as well.

What to review

Very little has changed -- I just wanted to ensure that any function that received a projection as a parameter would validate the projection.

Testing

Existing tests should suffice.

Fun gif

@cngonzalez cngonzalez requested a review from a team as a code owner September 16, 2025 13:54
@vercel
Copy link

vercel bot commented Sep 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sdk-docs Ready Ready Preview Comment Sep 16, 2025 3:11pm
sdk-kitchensink-react Ready Ready Preview Comment Sep 16, 2025 3:11pm

@cngonzalez cngonzalez requested a review from Copilot September 16, 2025 14:24
@cngonzalez cngonzalez enabled auto-merge (squash) September 16, 2025 14:24
Copy link

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 changes the ValidProjection type from a strict template literal type {${string}} to a more flexible string type to reduce user confusion and type errors. The change deprecates the original type while maintaining backward compatibility.

Key changes:

  • Deprecates the strict template literal ValidProjection type and changes it to string
  • Updates all function signatures to use string instead of ValidProjection for projection parameters
  • Adds runtime validation through validateProjection function calls

Reviewed Changes

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

Show a summary per file
File Description
packages/react/src/hooks/projection/useDocumentProjection.ts Updates hook generic constraints from ValidProjection to string
packages/react/src/hooks/projection/useDocumentProjection.test.tsx Updates test component type signatures to use string instead of ValidProjection
packages/core/src/projection/util.ts Changes validateProjection return type from ValidProjection to string
packages/core/src/projection/types.ts Deprecates ValidProjection type and redefines it as string
packages/core/src/projection/resolveProjection.ts Updates function generic constraint from ValidProjection to string
packages/core/src/projection/resolveProjection.test.ts Updates test to use plain string instead of ValidProjection type assertion
packages/core/src/projection/projectionQuery.ts Adds runtime validation call and updates type references
packages/core/src/projection/projectionQuery.test.ts Updates test variable types from ValidProjection to string
packages/core/src/projection/getProjectionState.ts Updates function generic constraints from ValidProjection to string

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


/**
* @public
* @deprecated
Copy link
Member

Choose a reason for hiding this comment

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

(question) do we want to mark this as deprecated or do we want to mark the version that this goes out with as a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can certainly use it as a reason to go up a version but I can't think of a scenario in which this might break someone's builds. The type has become more permissive so anyone who used ValidProjection explicitly shouldn't get any type errors, I don't think (maybe some linting against deprecations?)...

Copy link
Member

Choose a reason for hiding this comment

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

Good point, it likely would never cause any issues for users. I think I would rather remove it than mark it as deprecated in this case. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think removing an export would be a breaking change and require going up a version. We can do that too but maybe want to strategize on breaking changes first.

It would be good to add a todo list item to remove all deprecated types when we go up a version, certainly.

@cngonzalez cngonzalez merged commit 2079b36 into main Sep 18, 2025
27 of 29 checks passed
@cngonzalez cngonzalez deleted the fix/sdk-572/fix-typescript-issue-with-projection-strings branch September 18, 2025 19:00
@squiggler squiggler bot mentioned this pull request Sep 18, 2025
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