types(reactivity): computed types remove as (#367)

This commit is contained in:
相学长 2019-10-24 23:37:52 +08:00 committed by Evan You
parent 42bf9ca3e5
commit abfb2ec8ed

View File

@ -25,17 +25,20 @@ export function computed<T>(
export function computed<T>( export function computed<T>(
getterOrOptions: ComputedGetter<T> | WritableComputedOptions<T> getterOrOptions: ComputedGetter<T> | WritableComputedOptions<T>
) { ) {
const isReadonly = isFunction(getterOrOptions) let getter: ComputedGetter<T>
const getter = isReadonly let setter: ComputedSetter<T>
? (getterOrOptions as ComputedGetter<T>)
: (getterOrOptions as WritableComputedOptions<T>).get if (isFunction(getterOrOptions)) {
const setter = isReadonly getter = getterOrOptions
? __DEV__ setter = __DEV__
? () => { ? () => {
console.warn('Write operation failed: computed value is readonly') console.warn('Write operation failed: computed value is readonly')
} }
: NOOP : NOOP
: (getterOrOptions as WritableComputedOptions<T>).set } else {
getter = getterOrOptions.get
setter = getterOrOptions.set
}
let dirty = true let dirty = true
let value: T let value: T