Add helper type for remote function form enhancement callbacks
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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