-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
breaking: conditional ActionReturn type if Parameter is void #7442
Changes from 4 commits
3cb9dcf
1a21197
34f7b95
99764b2
5ee6087
5320874
0058204
abcc7c9
f1d3b50
608cc0e
3067fe8
45a3f39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,8 +17,8 @@ | |||||
* | ||||||
* Docs: https://svelte.dev/docs#template-syntax-element-directives-use-action | ||||||
*/ | ||||||
export interface ActionReturn<Parameter = any> { | ||||||
update?: (parameter: Parameter) => void; | ||||||
interface ActionReturn<Parameter = void> { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
not sure why this change slipped in (might have been an oversight by me), I think it's better to revert it to the previous version. |
||||||
update?: void extends Parameter ? undefined : (parameter: Parameter) => void; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use |
||||||
destroy?: () => void; | ||||||
} | ||||||
|
||||||
|
@@ -28,15 +28,20 @@ export interface ActionReturn<Parameter = any> { | |||||
* The following example defines an action that only works on `<div>` elements | ||||||
* and optionally accepts a parameter which it has a default value for: | ||||||
* ```ts | ||||||
* export const myAction: Action<HTMLDivElement, { someProperty: boolean }> = (node, param = { someProperty: true }) => { | ||||||
* export const myAction: Action<HTMLDivElement, undefined | { someProperty: boolean }> = (node, param = { someProperty: true }) => { | ||||||
ignatiusmb marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
* // ... | ||||||
* } | ||||||
* ``` | ||||||
* You can return an object with methods `update` and `destroy` from the function. | ||||||
* If your action doesn't accept a parameter, type if as `Action<HTMLElement, void>`. | ||||||
ignatiusmb marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
* | ||||||
* You can return an object with methods `update` (if the action accepts a parameter) and `destroy` from the function. | ||||||
* See interface `ActionReturn` for more details. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't |
||||||
* | ||||||
* Docs: https://svelte.dev/docs#template-syntax-element-directives-use-action | ||||||
*/ | ||||||
export interface Action<Element = HTMLElement, Parameter = any> { | ||||||
<Node extends Element>(node: Node, parameter?: Parameter): void | ActionReturn<Parameter>; | ||||||
} | ||||||
export type Action<Element = HTMLElement, Parameter = any> = | ||||||
void extends Parameter | ||||||
? <Node extends Element>(node: Node) => void | ActionReturn<Parameter> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||||||
: undefined extends Parameter | ||||||
? <Node extends Element>(node: Node, parameter?: Parameter) => void | ActionReturn<Parameter> | ||||||
: <Node extends Element>(node: Node, parameter: Parameter) => void | ActionReturn<Parameter>; | ||||||
ignatiusmb marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is not needed because everywhere a vaule gets passed