Explorar el Código

type: improve typing (#177)

扩散性百万甜面包 hace 6 años
padre
commit
def27239bd

+ 1 - 2
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<T> extends Ref<T> {
+export interface ComputedRef<T> extends WritableComputedRef<T> {
   readonly value: UnwrapNestedRefs<T>
-  readonly effect: ReactiveEffect
 }
 
 export interface WritableComputedRef<T> extends Ref<T> {

+ 1 - 2
packages/reactivity/src/reactive.ts

@@ -61,8 +61,7 @@ export function reactive(target: object) {
 
 export function readonly<T extends object>(
   target: T
-): Readonly<UnwrapNestedRefs<T>>
-export function readonly(target: object) {
+): Readonly<UnwrapNestedRefs<T>> {
   // value is a mutable observable, retrieve its original and return
   // a readonly version.
   if (reactiveToRaw.has(target)) {

+ 4 - 4
packages/reactivity/src/ref.ts

@@ -5,12 +5,12 @@ import { reactive } from './reactive'
 
 export const refSymbol = Symbol(__DEV__ ? 'refSymbol' : undefined)
 
-export interface Ref<T> {
+export interface Ref<T = any> {
   [refSymbol]: true
   value: UnwrapNestedRefs<T>
 }
 
-export type UnwrapNestedRefs<T> = T extends Ref<any> ? T : UnwrapRef<T>
+export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
 
 const convert = (val: any): any => (isObject(val) ? reactive(val) : val)
 
@@ -30,7 +30,7 @@ export function ref<T>(raw: T): Ref<T> {
   return v as Ref<T>
 }
 
-export function isRef(v: any): v is Ref<any> {
+export function isRef(v: any): v is Ref {
   return v ? v[refSymbol] === true : false
 }
 
@@ -73,7 +73,7 @@ export type UnwrapRef<T> = {
   array: T extends Array<infer V> ? Array<UnwrapRef<V>> : T
   object: { [K in keyof T]: UnwrapRef<T[K]> }
   stop: T
-}[T extends Ref<any>
+}[T extends Ref
   ? 'ref'
   : T extends Array<any>
     ? 'array'

+ 2 - 2
packages/runtime-core/src/createRenderer.ts

@@ -1767,8 +1767,8 @@ export function createRenderer<
   }
 
   function setRef(
-    ref: string | Function | Ref<any>,
-    oldRef: string | Function | Ref<any> | null,
+    ref: string | Function | Ref,
+    oldRef: string | Function | Ref | null,
     parent: ComponentInternalInstance,
     value: HostNode | ComponentPublicInstance | null
   ) {

+ 1 - 1
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<any> | Function
+  ref?: string | Ref | Function
   // used to differ from a single VNode object as children
   _isVNode?: never
   // used to differ from Array children