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

refactor: deduplicate schema optional types #2788

Conversation

vinassefranche
Copy link
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Followup of this comment on a previous P.R.

I did not add any changeset as it's supposed to be an internal refactor but, as shown in the update of the types' tests, there's a small potential external change so tell me if you think I should add one.

Related

  • Related Issue #
  • Closes #

Copy link

changeset-bot bot commented May 20, 2024

⚠️ No Changeset found

Latest commit: 8c77021

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -1850,134 +1850,85 @@ export const optionalToOptional = <FA, FI, FR, TA, TI, TR>(
)
)

type OptionalOptions<A> = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a huge fan of the name. Tell me if you have a better idea.

@@ -704,7 +704,7 @@ S.Struct({
})

// $ExpectType Struct<{ a: PropertySignature<":", "a" | "b", never, "?:", "a" | "b", true, never>; }>
S.Struct({ a: S.optional(S.Literal("a", "b"), { default: () => "a", exact: true }) })
S.Struct({ a: S.optional(S.Literal("a", "b"), { default: () => "a" as const, exact: true }) })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not completely sure why it was needed but as it was done for the other overload, I thought it was fine to add as const

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd revert this change, it's good to know that as const is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was actually needed with my change. If I revert it, I have an error:
image
Any idea where this could come from?
I don't have the issue if I only extract OptionalOptions. It comes when I extract OptionalReturnType.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, sorry, I read it wrong. I thought it was done for consistency, not because it was causing a new error. ok, let me see what could be causing it...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tries a few in or out in the OptionalOptions type but without success

Copy link
Contributor

Choose a reason for hiding this comment

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

The issue seems related to default being a lazy arg () => A
I have an idea to solve the issue, but it involves quite a refactoring. I'll send another PR to replace this one

@gcanti
Copy link
Contributor

gcanti commented May 21, 2024

Closing in favour of #2794

@gcanti gcanti closed this May 21, 2024
@vinassefranche vinassefranche deleted the deduplicate-schema-optional-types branch May 21, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants