-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) add experimental $$Events and strictEvents support (#1054)
$$Events lets the user define all events that a component can dispatch. If createEventDispatcher is not typed, the $$Events definition is added to it under the hood for type checking. strictEvents can be used when the user is sure that there are no other events besides the one from createEventDispatcher and forwarded events - this removes the custom event fallback typing. #442 #424 sveltejs/rfcs#38
- Loading branch information
1 parent
1992d63
commit b0d3f69
Showing
31 changed files
with
480 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ge-server/test/plugins/typescript/testfiles/completions/component-events-interface.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<script lang="ts"> | ||
interface ComponentEvents { | ||
interface $$Events { | ||
a: CustomEvent<boolean>; | ||
/** | ||
* TEST | ||
|
17 changes: 17 additions & 0 deletions
17
packages/language-server/test/plugins/typescript/testfiles/diagnostics/$$events.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts"> | ||
import { createEventDispatcher } from 'svelte'; | ||
interface $$Events { | ||
foo: CustomEvent<string>; | ||
click: MouseEvent; | ||
} | ||
const dispatch = createEventDispatcher(); | ||
// valid | ||
dispatch('foo', 'bar'); | ||
// invalid | ||
dispatch('foo', true); | ||
dispatch('click'); | ||
</script> | ||
|
||
<button on:click>click</button> |
8 changes: 8 additions & 0 deletions
8
...language-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-$$events.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script lang="ts"> | ||
import Events from './$$events.svelte'; | ||
</script> | ||
|
||
<!-- valid --> | ||
<Events on:click={e => e} on:foo={e => e.detail === 'bar'} /> | ||
<!-- invalid --> | ||
<Events on:bar={e => e} on:foo={e => e.detail === true} /> |
8 changes: 8 additions & 0 deletions
8
...uage-server/test/plugins/typescript/testfiles/diagnostics/diagnostics-strictEvents.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script lang="ts"> | ||
import StrictEvents from './strictEvents.svelte'; | ||
</script> | ||
|
||
<!-- valid --> | ||
<StrictEvents on:foo={e => e} on:click={e => e} /> | ||
<!-- invalid --> | ||
<StrictEvents on:bar={e => e} /> |
8 changes: 8 additions & 0 deletions
8
packages/language-server/test/plugins/typescript/testfiles/diagnostics/strictEvents.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script strictEvents> | ||
import { createEventDispatcher } from 'svelte'; | ||
const dispatch = createEventDispatcher(); | ||
dispatch('foo', 'bar'); | ||
</script> | ||
|
||
<button on:click>click</button> |
2 changes: 1 addition & 1 deletion
2
...ges/language-server/test/plugins/typescript/testfiles/hover/hover-events-interface.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<script lang="ts"> | ||
interface ComponentEvents { | ||
interface $$Events { | ||
a: CustomEvent<boolean>; | ||
/** | ||
* TEST | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.