Description
Motivation
Hi,
when using TypeScript with svelte, component events aren't automatically typed - e. g. you can have an on:nonexistent={() => {}}
handle for a non-existent event. However, svelte does check this, if the opening script tag of the child component has the strictEvents
attribute. (<script lang="ts" strictEvents>
).
I propose to add a rule that would enforce this.
Description
The rule should enforce that components have the strictEvents
attribute present in their opening svelte tag.
I propose several an option to choose for which components the attribute should be enforced:
- Require the attribute on all components. This makes sense since for a component that does not dispatch any event, the attribute still makes svelte check that no event listeners are present. I propose that this should be the default.
- Only check components that actually dispatch an event - this would probably be more complicated to implement
Additional note: For some components that have event mixins, the strictEvents
attribute does not work and you have to declare the $$Events
interface. In that case, I think the rule shouldn't fire - so effectively, it would require either the strictEvents
attribute or a manually declared interface $$Events
for the component.
Examples
<!-- ✓ GOOD -->
<script lang="ts" strictEvents>
</script>
<script lang="ts">
interface $$Events {}
</script>
<!-- ✗ BAD -->
<script lang="ts">
</script>
Additional comments
The relevant RFC.