types: improve type for WatchHandler (#160)
This commit is contained in:
parent
ff0f3bdf7c
commit
016231d09f
@ -116,11 +116,11 @@ export type ExtractComputedReturns<T extends any> = {
|
|||||||
: ReturnType<T[key]>
|
: ReturnType<T[key]>
|
||||||
}
|
}
|
||||||
|
|
||||||
type WatchHandler = (
|
export type WatchHandler<T = any> = (
|
||||||
val: any,
|
val: T,
|
||||||
oldVal: any,
|
oldVal: T,
|
||||||
onCleanup: CleanupRegistrator
|
onCleanup: CleanupRegistrator
|
||||||
) => void
|
) => any
|
||||||
|
|
||||||
type ComponentWatchOptions = Record<
|
type ComponentWatchOptions = Record<
|
||||||
string,
|
string,
|
||||||
|
@ -20,6 +20,7 @@ import {
|
|||||||
} from './errorHandling'
|
} from './errorHandling'
|
||||||
import { onBeforeUnmount } from './apiLifecycle'
|
import { onBeforeUnmount } from './apiLifecycle'
|
||||||
import { queuePostRenderEffect } from './createRenderer'
|
import { queuePostRenderEffect } from './createRenderer'
|
||||||
|
import { WatchHandler } from './apiOptions'
|
||||||
|
|
||||||
export interface WatchOptions {
|
export interface WatchOptions {
|
||||||
lazy?: boolean
|
lazy?: boolean
|
||||||
@ -49,7 +50,7 @@ export function watch(effect: SimpleEffect, options?: WatchOptions): StopHandle
|
|||||||
// overload #2: single source + cb
|
// overload #2: single source + cb
|
||||||
export function watch<T>(
|
export function watch<T>(
|
||||||
source: WatcherSource<T>,
|
source: WatcherSource<T>,
|
||||||
cb: (newValue: T, oldValue: T, onCleanup: CleanupRegistrator) => any,
|
cb: WatchHandler<T>,
|
||||||
options?: WatchOptions
|
options?: WatchOptions
|
||||||
): StopHandle
|
): StopHandle
|
||||||
|
|
||||||
@ -65,14 +66,9 @@ export function watch<T extends WatcherSource<unknown>[]>(
|
|||||||
): StopHandle
|
): StopHandle
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
export function watch(
|
export function watch<T = any>(
|
||||||
effectOrSource:
|
effectOrSource: WatcherSource<T> | WatcherSource<T>[] | SimpleEffect,
|
||||||
| WatcherSource<unknown>
|
cbOrOptions?: WatchHandler<T> | WatchOptions,
|
||||||
| WatcherSource<unknown>[]
|
|
||||||
| SimpleEffect,
|
|
||||||
cbOrOptions?:
|
|
||||||
| ((value: any, oldValue: any, onCleanup: CleanupRegistrator) => any)
|
|
||||||
| WatchOptions,
|
|
||||||
options?: WatchOptions
|
options?: WatchOptions
|
||||||
): StopHandle {
|
): StopHandle {
|
||||||
if (isFunction(cbOrOptions)) {
|
if (isFunction(cbOrOptions)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user