mirror of https://github.com/sveltejs/svelte
fix: better types for `on` (#12053)
- give autocompletion for types and more precise event types for html elements - allow to pass other kinds of event target nodes, like window closes #12027 fixes #12045pull/12056/head
parent
59486beb29
commit
f1d8ed64fd
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: better types for `on`
|
@ -0,0 +1,28 @@
|
|||||||
|
import { on } from 'svelte/events';
|
||||||
|
|
||||||
|
// ---------------- on
|
||||||
|
|
||||||
|
on(document.body, 'click', (e) => e.button);
|
||||||
|
|
||||||
|
on(
|
||||||
|
document.body,
|
||||||
|
'clidck',
|
||||||
|
(e) =>
|
||||||
|
// @ts-expect-error
|
||||||
|
e.button
|
||||||
|
);
|
||||||
|
|
||||||
|
on(
|
||||||
|
window,
|
||||||
|
'click',
|
||||||
|
(e) =>
|
||||||
|
// @ts-expect-error ideally we'd know this is a MouseEvent here, too, but for keeping the types sane, we currently don't
|
||||||
|
e.button
|
||||||
|
);
|
||||||
|
|
||||||
|
on(
|
||||||
|
// @ts-expect-error
|
||||||
|
'asd',
|
||||||
|
'asd',
|
||||||
|
(e) => e
|
||||||
|
);
|
Loading…
Reference in new issue