Skip to content

Commit 217cc54

Browse files
committed
fix(asyncComputed): fix types for AsyncComputedOptions
1 parent 46a2bf5 commit 217cc54

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

packages/core/computedAsync/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,14 @@ describe('computedAsync', () => {
285285
await vi.advanceTimersByTimeAsync(10)
286286
expect(uppercase.value).toBe('FINAL')
287287
})
288+
289+
it('type when lazy is a boolean', async () => {
290+
const lazy: boolean = true
291+
const data = [] as string[]
292+
const data1 = computedAsync(async () => data, [], { lazy })
293+
const data2 = computedAsync(async () => data, undefined, { lazy })
294+
295+
expectTypeOf(data1).toEqualTypeOf<ComputedRef<string[]>>()
296+
expectTypeOf(data2).toEqualTypeOf<ComputedRef<string[] | undefined>>()
297+
})
288298
})

packages/core/computedAsync/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import {
1616
*/
1717
export type AsyncComputedOnCancel = (cancelCallback: Fn) => void
1818

19-
export interface AsyncComputedOptions {
19+
export interface AsyncComputedOptions<Lazy = boolean> {
2020
/**
2121
* Should value be evaluated lazily
2222
*
2323
* @default false
2424
*/
25-
lazy?: boolean
25+
lazy?: Lazy
2626

2727
/**
2828
* Ref passed to receive the updated of async evaluation
@@ -63,22 +63,22 @@ export interface AsyncComputedOptions {
6363
export function computedAsync<T>(
6464
evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>,
6565
initialState: T,
66-
optionsOrRef: AsyncComputedOptions & { lazy: true },
66+
optionsOrRef: AsyncComputedOptions<true>,
6767
): ComputedRef<T>
6868
export function computedAsync<T>(
6969
evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>,
7070
initialState: undefined,
71-
optionsOrRef: AsyncComputedOptions & { lazy: true },
71+
optionsOrRef: AsyncComputedOptions<true>,
7272
): ComputedRef<T | undefined>
7373
export function computedAsync<T>(
7474
evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>,
7575
initialState: T,
76-
optionsOrRef?: Ref<boolean> | (AsyncComputedOptions & { lazy?: false | undefined }),
76+
optionsOrRef?: Ref<boolean> | AsyncComputedOptions,
7777
): Ref<T>
7878
export function computedAsync<T>(
7979
evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>,
8080
initialState?: undefined,
81-
optionsOrRef?: Ref<boolean> | (AsyncComputedOptions & { lazy?: false | undefined }),
81+
optionsOrRef?: Ref<boolean> | AsyncComputedOptions,
8282
): Ref<T | undefined>
8383
export function computedAsync<T>(
8484
evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>,

0 commit comments

Comments
 (0)