sveltejs / sveltejs/kit

Add helper type for remote function form enhancement callbacks

Open
#14,924 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

forms types / typescript
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

When working with large callback functions, I prefer defining them in the script tag rather than inlining them in the markup. However, I couldn't find a built-in helper type for typing a form enhancement callback.

Creating it manually is no big deal but it would be very nice if I could just import it.

<script lang="ts">
  import { remoteFn } from './example.remote';
  import type { RemoteForm } from '@sveltejs/kit';

  type RemoteFormEnhance<T extends RemoteForm<any, any>> = Parameters<Awaited<T>['enhance']>[0];

  type EnhanceCallback = RemoteFormEnhance<typeof remoteFn>;

  const onSubmit: EnhanceCallback = () => {
    // Lots of code
  };
</script>

<form {...remoteFn.enhance(onSubmit)}>
</form>
Describe the proposed solution

Define helper type internally and export it.

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names RemoteForm, remoteFn.enhance, and the proposed RemoteFormEnhance type; start by locating the existing remote-form type exports and their public entry point. Export the callback helper type so a script-defined onSubmit can be typed and imported from @sveltejs/kit.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.