wip: improve computed typing + test for setters

This commit is contained in:
Evan You
2019-08-21 12:01:05 -04:00
parent 8d99ab1ff8
commit 0aff144f93
6 changed files with 60 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect'
import { UnwrapNestedRefs, knownRefs } from './ref'
import { UnwrapNestedRefs, knownRefs, Ref } from './ref'
import { isFunction } from '@vue/shared'
export interface ComputedRef<T> {
@@ -12,9 +12,11 @@ export interface ComputedOptions<T> {
set: (v: T) => void
}
export function computed<T>(getter: () => T): ComputedRef<T>
export function computed<T>(options: ComputedOptions<T>): Ref<T>
export function computed<T>(
getterOrOptions: (() => T) | ComputedOptions<T>
): ComputedRef<T> {
): Ref<T> {
const isReadonly = isFunction(getterOrOptions)
const getter = isReadonly
? (getterOrOptions as (() => T))