types: improve computed types (#343)
This commit is contained in:
committed by
Evan You
parent
1f4937c2fd
commit
74d8c5919d
@@ -30,7 +30,11 @@ import {
|
||||
DebuggerHook,
|
||||
ErrorCapturedHook
|
||||
} from './apiLifecycle'
|
||||
import { reactive } from '@vue/reactivity'
|
||||
import {
|
||||
reactive,
|
||||
ComputedGetter,
|
||||
WritableComputedOptions
|
||||
} from '@vue/reactivity'
|
||||
import { ComponentObjectPropsOptions, ExtractPropTypes } from './componentProps'
|
||||
import { Directive } from './directives'
|
||||
import { ComponentPublicInstance } from './componentProxy'
|
||||
@@ -100,14 +104,10 @@ export type ComponentOptions =
|
||||
// TODO legacy component definition also supports constructors with .options
|
||||
type LegacyComponent = ComponentOptions
|
||||
|
||||
export interface ComputedOptions {
|
||||
[key: string]:
|
||||
| Function
|
||||
| {
|
||||
get: Function
|
||||
set: Function
|
||||
}
|
||||
}
|
||||
export type ComputedOptions = Record<
|
||||
string,
|
||||
ComputedGetter<any> | WritableComputedOptions<any>
|
||||
>
|
||||
|
||||
export interface MethodOptions {
|
||||
[key: string]: Function
|
||||
|
||||
@@ -26,7 +26,8 @@ import {
|
||||
ComputedRef,
|
||||
WritableComputedOptions,
|
||||
ReactiveEffect,
|
||||
WritableComputedRef
|
||||
WritableComputedRef,
|
||||
ComputedGetter
|
||||
} from '@vue/reactivity'
|
||||
|
||||
import { currentInstance } from './component'
|
||||
@@ -39,12 +40,12 @@ export function recordEffect(effect: ReactiveEffect) {
|
||||
}
|
||||
}
|
||||
|
||||
export function computed<T>(getter: () => T): ComputedRef<T>
|
||||
export function computed<T>(getter: ComputedGetter<T>): ComputedRef<T>
|
||||
export function computed<T>(
|
||||
options: WritableComputedOptions<T>
|
||||
): WritableComputedRef<T>
|
||||
export function computed<T>(
|
||||
getterOrOptions: (() => T) | WritableComputedOptions<T>
|
||||
getterOrOptions: ComputedGetter<T> | WritableComputedOptions<T>
|
||||
) {
|
||||
const c = _computed(getterOrOptions as any)
|
||||
recordEffect(c.effect)
|
||||
|
||||
Reference in New Issue
Block a user