Skip to content

Commit bc4aca9

Browse files
authored
fix(computedWithControl): allow different types in watch sources array (#5184)
1 parent 7fb7a05 commit bc4aca9

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

packages/shared/computedWithControl/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,17 @@ describe('computedWithControl', () => {
108108

109109
expect(computed.value).toBe(42)
110110
})
111+
112+
it('can watch an array of multiple sources', () => {
113+
const trigger1 = shallowRef(1)
114+
const trigger2 = shallowRef('2')
115+
116+
const computed = computedWithControl([trigger1, trigger2], () => trigger1.value + trigger2.value)
117+
118+
expect(computed.value).toBe('12')
119+
120+
trigger1.value = 2
121+
122+
expect(computed.value).toBe('22')
123+
})
111124
})

packages/shared/computedWithControl/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ComputedGetter, ComputedRef, WatchOptions, WatchSource, WritableComputedOptions, WritableComputedRef } from 'vue'
1+
import type { ComputedGetter, ComputedRef, MultiWatchSources, WatchOptions, WatchSource, WritableComputedOptions, WritableComputedRef } from 'vue'
22
import type { Fn } from '../utils'
33
import { customRef, watch } from 'vue'
44

@@ -14,14 +14,14 @@ export interface WritableComputedRefWithControl<T> extends WritableComputedRef<T
1414

1515
export type ComputedWithControlRef<T = any> = ComputedRefWithControl<T> | WritableComputedRefWithControl<T>
1616

17-
export function computedWithControl<T, S>(
18-
source: WatchSource<S> | WatchSource<S>[],
17+
export function computedWithControl<T>(
18+
source: WatchSource | MultiWatchSources,
1919
fn: ComputedGetter<T>,
2020
options?: WatchOptions
2121
): ComputedRefWithControl<T>
2222

23-
export function computedWithControl<T, S>(
24-
source: WatchSource<S> | WatchSource<S>[],
23+
export function computedWithControl<T>(
24+
source: WatchSource | MultiWatchSources,
2525
fn: WritableComputedOptions<T>,
2626
options?: WatchOptions
2727
): WritableComputedRefWithControl<T>
@@ -32,8 +32,8 @@ export function computedWithControl<T, S>(
3232
* @param source
3333
* @param fn
3434
*/
35-
export function computedWithControl<T, S>(
36-
source: WatchSource<S> | WatchSource<S>[],
35+
export function computedWithControl<T>(
36+
source: WatchSource | MultiWatchSources,
3737
fn: ComputedGetter<T> | WritableComputedOptions<T>,
3838
options: WatchOptions = {},
3939
): ComputedWithControlRef<T> {

0 commit comments

Comments
 (0)