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

Support type hints in InferSchemaType #14008

Merged
merged 3 commits into from Dec 3, 2023

Conversation

JavaScriptBach
Copy link
Contributor

@JavaScriptBach JavaScriptBach commented Oct 25, 2023

Summary

Implement type hints for InferSchemaType. Motivation detailed in #14002. It will let users:

  1. Define stronger types than what InferSchemaType would otherwise infer, in cases where the user knows more about the data being stored.
  2. Define a correct type in cases when InferSchemaType gives the wrong type.

Examples

Added a test

PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
unknown;
type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueType> = {}, TypeKey extends string = DefaultSchemaOptions['typeKey'], TypeHint = never> =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change looks large, but what it boils down to is:

"If TypeHint is not never, use the TypeHint, otherwise infer it as we did before"

@vkarpov15 vkarpov15 changed the base branch from master to 8.1 December 3, 2023 22:11
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.

LGTM, merging into 8.1 👍

@vkarpov15 vkarpov15 added this to the 8.1 milestone Dec 3, 2023
@vkarpov15 vkarpov15 merged commit b3ef1d8 into Automattic:8.1 Dec 3, 2023
3 checks passed
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.

None yet

2 participants