Skip to content

infer correct type for schema.String<T>({ required: false })#69

Merged
zxch3n merged 2 commits intoloro-dev:mainfrom
kimjoar:kim/fix-schema-string-generic-inference
Mar 24, 2026
Merged

infer correct type for schema.String<T>({ required: false })#69
zxch3n merged 2 commits intoloro-dev:mainfrom
kimjoar:kim/fix-schema-string-generic-inference

Conversation

@kimjoar
Copy link
Copy Markdown
Contributor

@kimjoar kimjoar commented Jan 6, 2026

When using schema.String({ required: false }) with only one type parameter, TypeScript would default the second type parameter O to {} instead of inferring it from the argument. This caused the inferred type to be CustomType instead of CustomType | undefined.

Fixed by adding function overloads that specifically handle the { required: false } case, allowing the options type to be captured correctly without requiring explicit type parameters.

🤖 Generated with Claude Code

…e })

When using schema.String<CustomType>({ required: false }) with only one
type parameter, TypeScript would default the second type parameter O to {}
instead of inferring it from the argument. This caused the inferred type
to be CustomType instead of CustomType | undefined.

Fixed by adding function overloads that specifically handle the
{ required: false } case, allowing the options type to be captured
correctly without requiring explicit type parameters.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kimjoar
Copy link
Copy Markdown
Contributor Author

kimjoar commented Jan 19, 2026

Anything I can provide to help this land?

…restore default for overload 3

- Overload 2 now uses `O extends SchemaOptions & { required: false }` instead of
  hardcoding the return type to `{ required: false }`, so extra options aren't lost
- Overload 3 restores the original default of `{}` instead of `SchemaOptions`

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zxch3n zxch3n merged commit e24056d into loro-dev:main Mar 24, 2026
1 check passed
@github-actions github-actions Bot mentioned this pull request Mar 24, 2026
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