-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking: improve types for
createEventDispatcher
(#7224)
--------- Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
- Loading branch information
1 parent
573784c
commit d6bcddd
Showing
6 changed files
with
95 additions
and
14 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { createEventDispatcher } from '$runtime/internal/lifecycle'; | ||
|
||
const dispatch = createEventDispatcher<{ | ||
loaded: never | ||
change: string | ||
valid: boolean | ||
optional: number | null | ||
}>(); | ||
|
||
// @ts-expect-error: dispatch invalid event | ||
dispatch('some-event'); | ||
|
||
dispatch('loaded'); | ||
dispatch('loaded', null); | ||
dispatch('loaded', undefined); | ||
dispatch('loaded', undefined, { cancelable: true }); | ||
// @ts-expect-error: no detail accepted | ||
dispatch('loaded', 123); | ||
|
||
// @ts-expect-error: detail not provided | ||
dispatch('change'); | ||
dispatch('change', 'string'); | ||
dispatch('change', 'string', { cancelable: true }); | ||
// @ts-expect-error: wrong type of detail | ||
dispatch('change', 123); | ||
// @ts-expect-error: wrong type of detail | ||
dispatch('change', undefined); | ||
|
||
dispatch('valid', true); | ||
dispatch('valid', true, { cancelable: true }); | ||
// @ts-expect-error: wrong type of detail | ||
dispatch('valid', 'string'); | ||
|
||
dispatch('optional'); | ||
dispatch('optional', 123); | ||
dispatch('optional', 123, { cancelable: true }); | ||
dispatch('optional', null); | ||
dispatch('optional', undefined); | ||
dispatch('optional', undefined, { cancelable: true }); | ||
// @ts-expect-error: wrong type of optional detail | ||
dispatch('optional', 'string'); | ||
// @ts-expect-error: wrong type of option | ||
dispatch('optional', undefined, { cancelabled: true }); |
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,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "../..", | ||
"baseUrl": "../../", | ||
"paths": { | ||
"$runtime/*": ["src/runtime/*"] | ||
}, | ||
// enable strictest options | ||
"allowUnreachableCode": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"strict": true, | ||
}, | ||
"include": ["."] | ||
} |