Skip to content

v1 The type after transition transform has changed #1109

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

Closed
yanskun opened this issue Mar 25, 2025 · 3 comments
Closed

v1 The type after transition transform has changed #1109

yanskun opened this issue Mar 25, 2025 · 3 comments
Assignees
Labels
duplicate This issue or pull request already exists

Comments

@yanskun
Copy link

yanskun commented Mar 25, 2025

import {
  object,
  string,
  optional,
  pipe,
  transform,
  InferOutput,
} from "valibot";

const SchemaA = object({
  key: pipe(
    optional(string()),
    transform((input) => (input === undefined ? "empty" : input)),
  ),
});
type SchemaAType = InferOutput<typeof SchemaA>;

const SchemaB = pipe(
  object({
    key: optional(string()),
  }),
  transform((input) => ({
    key: input.key === undefined ? "empty" : input.key,
  })),
);
type SchemaBType = InferOutput<typeof SchemaB>;

When defined as above

Image Image

At 0.42.1, both were like SchemaBTyoe.
Is it a specification from v1 or a problem?

@fabian-hiller fabian-hiller self-assigned this Mar 25, 2025
@fabian-hiller fabian-hiller added the duplicate This issue or pull request already exists label Mar 25, 2025
@fabian-hiller
Copy link
Owner

See #1095

@fabian-hiller
Copy link
Owner

Depending on your goal you can define a default value via the second argument of optional or replace optional with undefinedable.

@yanskun
Copy link
Author

yanskun commented Mar 25, 2025

Thank you!

I didn't know about undefinedable. That's helpful.

@yanskun yanskun closed this as completed Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants