Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 1.54 KB

require-event-dispatcher-types.md

File metadata and controls

47 lines (32 loc) · 1.54 KB
pageClass sidebarDepth title description since
rule-details
0
svelte/require-event-dispatcher-types
require type parameters for `createEventDispatcher`
v2.16.0

svelte/require-event-dispatcher-types

require type parameters for createEventDispatcher

📖 Rule Details

This rule is aimed to enforce type parameters when calling createEventDispatcher. Adding types makes all dispatch calls as well as all event listeners typechecked. For more information, see the svelte docs.

<script lang="ts">
  /* eslint svelte/require-event-dispatcher-types: "error" */

  import { createEventDispatcher } from 'svelte';

  /* ✓ GOOD */
  const dispatch1 = createEventDispatcher<{ one: never; two: number }>();
  const dispatch2 = createEventDispatcher<Record<string, never>>();
  const dispatch3 = createEventDispatcher<any>();
  const dispatch4 = createEventDispatcher<unknown>();

  /* ✗ BAD */
  const dispatch5 = createEventDispatcher();
</script>

🔧 Options

Nothing.

🚀 Version

This rule was introduced in eslint-plugin-svelte v2.16.0

🔍 Implementation