In my Svelte input field, I have the following code:
<input
{type}
{placeholder}
on:input={(e) => emitChange(e)}
class="pl-2 w-full h-full bg-sand border border-midnight dark:bg-midnight"
/>
This input triggers the following function:
function emitChange(event: any) {
const text = event.target.value
dispatch("changeContent", {
text,
})
}
Now, I want to replace the any
type with the correct InputEvent
. However, my attempts to import InputEvent
from "svelte" failed with an error saying that it is not exported.
I then tried changing the function parameter to event: InputEvent
, but encountered an error stating that 'value' does not exist on type 'EventTarget'. Even though when I console log the event
, I can see a 'target' property with a value.
Further refining the function like this seems to work and provides some improvements:
function emitChange(event: any) {
console.log(event, "13rm")
const { value } = event.target as HTMLInputElement // improvement
const text = value
}