-
-
Notifications
You must be signed in to change notification settings - Fork 59
Closed
Labels
Description
Motivation
Hi,
when using svelte with TypeScript, it is possible to add types to events by typing the createEventDispatcher function so:
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher<{one: never, two: number}>();
dispatch("one"); // OK
dispatch("two", 3); // OK
dispatch("one", "Hello world"); // Fails
dispatch("two"); // Fails
dispatch("two", "Hello world"); // FailsI propose a rule that would require all calls to createEventDispatcher to include the templated type.
Description
The rule would trigger on any call of createEventDispatcher witchou the templated type
Examples
import { createEventDispatcher } from "svelte";
<!-- ✓ GOOD -->
const dispatch = createEventDispatcher<{one: never, two: number}>();
const dispatch = createEventDispatcher<any>();
const dispatch = createEventDispatcher<{}>();
<!-- ✗ BAD -->
const dispatch = createEventDispatcher();Additional comments
No response