Skip to content

Conversation

@dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Sep 17, 2025

Optional properties make the resulting type X | undefined which when turned into an intersection results in the never type. We therefore mark all properties as required while transforming the objects into their desired shape.

There's another adjacent bug: If you have an object only consisting of optional properties, e.g. {a?: string}, then RemoteFormInput extends it and the type is degraded to e.g. { [key: string]: RemoteFormIssues[] }. A fix to the "will recurse indefinetly" helper type solves this: we now check if the object keys match an index signature, and only bail in that case.

Also added a few tests

Fixes #14461


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:.

We need to make the result nonnullable, because else the optional properties make the resulting type `X | undefined` which when turned into an intersection results in the never type.
@changeset-bot
Copy link

changeset-bot bot commented Sep 17, 2025

🦋 Changeset detected

Latest commit: 263206d

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

@ottomated
Copy link
Contributor

Duplicate of #14458? I think my approach is less likely to create indefinite type nesting errors

@dummdidumm
Copy link
Member Author

Sorry for not seing that PR earlier - your solution looks similar with respect to preventing undefined from sneaking in. I chose to go with Required<T> instead (feels a bit "cleaner", purely aesthetic preference), and fixes and adjacent bug around false-positive "this is infinite"

@dummdidumm dummdidumm marked this pull request as ready for review September 18, 2025 12:24
@dummdidumm dummdidumm marked this pull request as draft September 18, 2025 13:50
@dummdidumm dummdidumm marked this pull request as ready for review September 18, 2025 15:14
@dummdidumm dummdidumm merged commit ff9cf14 into main Sep 18, 2025
22 checks passed
@dummdidumm dummdidumm deleted the form-types-fix branch September 18, 2025 15:28
@github-actions github-actions bot mentioned this pull request Sep 18, 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.

The remote form object's field method breaks when handling optional values in the schema

3 participants