Skip to content
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

createEventDispatcher definitions are not merged #921

Closed
dummdidumm opened this issue Mar 28, 2021 · 0 comments
Closed

createEventDispatcher definitions are not merged #921

dummdidumm opened this issue Mar 28, 2021 · 0 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@dummdidumm
Copy link
Member

It appears that only the last createEventDispatcher produces the type for the listener, they are not merged.

Example:

// Component Foo
const dispatchFoo = createEventDispatcher<{foo: string; bar: boolean}>();
const dispatchBar = createEventDispatcher<{bar: string; baz: string}>();

// Component Bar
// e is CustomEvent<any>
on:foo="{(e) => handleFoo(e.detail.bar)}"
// e is CustomEvent<{baz: string}>
on:bar="{(e) => handleBar(e.detail.bar)}"

The typescript compiler catches this as expected.

Changing the order produces different results.

if the createEventDispatcher order changes, then the typescript compiler does not catch the error.

// Component Foo
const dispatchBar = createEventDispatcher<{bar: string; baz: string}>();
const dispatchFoo = createEventDispatcher<{foo: string; bar: boolean}>();

// Component Bar
// e is CustomEvent<{bar: boolean}>
on:foo="{(e) => handleFoo(e.detail.bar)}"
// e is CustomEvent<any>
on:bar="{(e) => handleBar(e.detail.bar)}"

The typescript compiler does not catch the error since the type is now CustomEvent<any>.

Originally posted by @linuxuser586 in #424 (comment)

@dummdidumm dummdidumm added the bug Something isn't working label Mar 28, 2021
dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Apr 6, 2021
Merge definitions of multiple `createEventDispatcher`-instantations as well as bubbled events.
sveltejs#921
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Apr 6, 2021
dummdidumm added a commit that referenced this issue Apr 6, 2021
Merge definitions of multiple `createEventDispatcher`-instantations as well as bubbled events.
#921
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

1 participant