Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

svelte event parameter type for typescript

$
0
0

So new to svelte but it is so small it is perfect for a job i am working on.

Went for the typescript option: https://svelte.dev/blog/svelte-and-typescript

How or where can i find the types for custom component events:

A simple login component form:

<script lang="ts">  import { createEventDispatcher } from 'svelte'  const dispatch = createEventDispatcher()  let isSubmitting = false  const handleSubmit = (e: HTMLFormElement) => {    e.preventDefault()    isSubmitting = true    const payload = {      username: e.target.username.value,      password: e.target.password.value,    }    dispatch('submit', payload)  }</script><form on:submit={handleSubmit}><label for="username"><b>Username</b></label><input type="text" placeholder="Enter Username" name="username" required id="username"><label for="password"><b>Password</b></label><input type="password" placeholder="Enter Password" name="password" required id="password"><button type="submit" disabled={isSubmitting}>Login</button></form>

Included in another component to handle the submit:

<script lang="ts">  import Login from './molecules/Login.svelte'  const loginHandle = function (a: any) {    console.log(a)  }</script><main class="{open}">   {#if !authenticated}<Login on:submit={loginHandle}/>   {/if}</main>

Right now there is an ugly any added to the loginHandle but when dumping the event to console it looks to be very svelte specific.. where can i find the type?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>