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

Svelte typescripts does not see events emitted from actions #6995

Closed
jacobbogers opened this issue Dec 6, 2021 · 1 comment
Closed

Svelte typescripts does not see events emitted from actions #6995

jacobbogers opened this issue Dec 6, 2021 · 1 comment

Comments

@jacobbogers
Copy link

jacobbogers commented Dec 6, 2021

Describe the bug

I am trying to use actions on an input component
this normally works without typescript, but with typescript it cannot recognize the events emitted from the action

//FILE: checkable.ts, these is the action
export function checkable(node: HTMLElement): SvelteActionReturnType {

	function handleChange(e: Event & { target: { checked: boolean } }) {
		
		if (e.target?.checked) {
			node.dispatchEvent(new CustomEvent('checked'))
		}
		else {
			node.dispatchEvent(new CustomEvent('unchecked'));
		}
	}

	node.addEventListener('change', handleChange as (e: Event) => void);

	return {
		destroy() {
			node.removeEventListener('change', handleChange as (e: Event) => void);
		}
	};
}

** Note the events "change" is translated to 2 events "checked" and "unchecked" **

//FILE: ButtonSpecial.svelte
 <script lang="ts">
    import { checkable } from "./checkable"; 
</script>

 <input use:checkable on:checked on:unchecked type="checkbox" />


### Reproduction

Not applicable

### Logs

Type '{ onchecked: undefined; onunchecked: undefined; type: string; }' is not assignable to type 'SvelteInputProps'.
  Property 'onchecked' does not exist on type 'SvelteInputProps'. Did you mean 'checked'?ts(2322)

### System Info

```shell
Not applicable

Severity

blocking all usage of svelte

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

No branches or pull requests

2 participants