Skip to content

Conversation

@sillvva
Copy link
Contributor

@sillvva sillvva commented Oct 17, 2025

Discussed in #14745. The Invalid<Input> generic should be automatically based on the schema input type instead of the output type.

I and others have run into the issue where we're coercing date strings to actual Date objects, and that causes a type error when trying to do something like invalid.date("Invalid date"). In this case, invalid.date is of type never, because it only accepts string | number | boolean | File types. If it were based on the schema input type, that wouldn't be an issue.

const schema = z.object({
  date: z.coerce.date<string>(),
});

// Doesn't work. `invalid` is based on schema output type.
// It only accepts types: string | number | boolean | File
export const testForm = form(schema, (input, invalid) => {
  // input: Invalid<{ date: string }>
  // output: Invalid<{ date: Date }>
  invalid(invalid.date('Not valid'));
  //              ^^^^ Type 'never' has no call signatures.
});

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented Oct 17, 2025

🦋 Changeset detected

Latest commit: 18a5fc0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

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

@svelte-docs-bot
Copy link

@sillvva sillvva changed the title fix: update overload to set invalid type to schema input fix: update form overload to set invalid type to schema input Oct 17, 2025
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

thank you!

@dummdidumm dummdidumm merged commit c9b31d9 into sveltejs:main Oct 17, 2025
19 checks passed
@github-actions github-actions bot mentioned this pull request Oct 17, 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