Skip to content

(feat) (svelte2tsx) Type check event forward from element on component #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 28, 2020

Conversation

jasonlyu123
Copy link
Member

@jasonlyu123 jasonlyu123 commented Jul 12, 2020

Aims to be able to type-check events bubbled/forwarded from an element. https://svelte.dev/docs#on_element_event
Part of #304

Component.svelte

<button on:click></button>

Component2.svelte

<scirpt>
import Component2 from './Component2.svelte
</script>

<Component2 on:click={e => console.log(e)} /> <!--- type check here -->
  • Component event type check spec
  • Definition of element event forward in the component class
  • New Component event type check method
  • Component forward event again

@jasonlyu123
Copy link
Member Author

Can't get it to extract event type from $on method, Seems like we might still need to add a def property like $$props_def and $$slot_def

1. $on return off funciton
2. wildcard event is CustomEvent now
@jasonlyu123 jasonlyu123 marked this pull request as ready for review July 28, 2020 05:20
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! There is one problem that remains: When the user defines a custom event, it will not get picked up and it will throw a false type error:

<script>
  import { createEventDispatcher } from 'svelte';

  const dispatch = createEventDispatcher();
  dispatch('hello', 3);
</script>
<script>
  import Child from './Child.svelte';
</script>

<Child on:hello={e => e} /> // <--- throws an error

We somehow need to fall back to the generic Event interface in this case.

@dummdidumm dummdidumm self-requested a review July 28, 2020 12:18
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants