From: 扩散性百万甜面包 Date: Wed, 9 Oct 2019 18:01:53 +0000 (+0800) Subject: type: improve typing (#177) X-Git-Tag: v3.0.0-alpha.0~534 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=def27239bd18317a41a8914fb69baf51ca723fdb;p=thirdparty%2Fvuejs%2Fcore.git type: improve typing (#177) --- diff --git a/packages/reactivity/src/computed.ts b/packages/reactivity/src/computed.ts index 9f2ede3675..c1cf34cbb9 100644 --- a/packages/reactivity/src/computed.ts +++ b/packages/reactivity/src/computed.ts @@ -2,9 +2,8 @@ import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect' import { Ref, refSymbol, UnwrapNestedRefs } from './ref' import { isFunction, NOOP } from '@vue/shared' -export interface ComputedRef extends Ref { +export interface ComputedRef extends WritableComputedRef { readonly value: UnwrapNestedRefs - readonly effect: ReactiveEffect } export interface WritableComputedRef extends Ref { diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index b703154ee8..5fba512470 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -61,8 +61,7 @@ export function reactive(target: object) { export function readonly( target: T -): Readonly> -export function readonly(target: object) { +): Readonly> { // value is a mutable observable, retrieve its original and return // a readonly version. if (reactiveToRaw.has(target)) { diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 113696bd45..9e000d979a 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -5,12 +5,12 @@ import { reactive } from './reactive' export const refSymbol = Symbol(__DEV__ ? 'refSymbol' : undefined) -export interface Ref { +export interface Ref { [refSymbol]: true value: UnwrapNestedRefs } -export type UnwrapNestedRefs = T extends Ref ? T : UnwrapRef +export type UnwrapNestedRefs = T extends Ref ? T : UnwrapRef const convert = (val: any): any => (isObject(val) ? reactive(val) : val) @@ -30,7 +30,7 @@ export function ref(raw: T): Ref { return v as Ref } -export function isRef(v: any): v is Ref { +export function isRef(v: any): v is Ref { return v ? v[refSymbol] === true : false } @@ -73,7 +73,7 @@ export type UnwrapRef = { array: T extends Array ? Array> : T object: { [K in keyof T]: UnwrapRef } stop: T -}[T extends Ref +}[T extends Ref ? 'ref' : T extends Array ? 'array' diff --git a/packages/runtime-core/src/createRenderer.ts b/packages/runtime-core/src/createRenderer.ts index 3a90d1e0f4..8211a4bdc7 100644 --- a/packages/runtime-core/src/createRenderer.ts +++ b/packages/runtime-core/src/createRenderer.ts @@ -1767,8 +1767,8 @@ export function createRenderer< } function setRef( - ref: string | Function | Ref, - oldRef: string | Function | Ref | null, + ref: string | Function | Ref, + oldRef: string | Function | Ref | null, parent: ComponentInternalInstance, value: HostNode | ComponentPublicInstance | null ) { diff --git a/packages/runtime-core/src/h.ts b/packages/runtime-core/src/h.ts index 3a29607a58..5b32f3b7c6 100644 --- a/packages/runtime-core/src/h.ts +++ b/packages/runtime-core/src/h.ts @@ -50,7 +50,7 @@ h('div', null, {}) export interface RawProps { [key: string]: any key?: string | number - ref?: string | Ref | Function + ref?: string | Ref | Function // used to differ from a single VNode object as children _isVNode?: never // used to differ from Array children