|
1 | 1 | import { Data } from '../component'; |
2 | 2 | import { RefKey } from '../symbols'; |
3 | 3 | import { proxy, isPlainObject, warn } from '../utils'; |
4 | | -import { HasDefined } from '../types/basic'; |
5 | 4 | import { reactive, isReactive, shallowReactive } from './reactive'; |
6 | 5 | import { ComputedRef } from '../apis/computed'; |
7 | 6 |
|
@@ -79,24 +78,10 @@ export function createRef<T>(options: RefOption<T>) { |
79 | 78 | return Object.seal(new RefImpl<T>(options)); |
80 | 79 | } |
81 | 80 |
|
82 | | -type RefValue<T> = T extends Ref<infer V> ? V : UnwrapRef<T>; |
83 | | - |
84 | | -// without init value, explicit typed: a = ref<{ a: number }>() |
85 | | -// typeof a will be Ref<{ a: number } | undefined> |
| 81 | +export function ref<T extends object>(raw: T): T extends Ref ? T : Ref<UnwrapRef<T>>; |
| 82 | +export function ref<T>(raw: T): Ref<UnwrapRef<T>>; |
86 | 83 | export function ref<T = any>(): Ref<T | undefined>; |
87 | | -// with null as init value: a = ref<{ a: number }>(null); |
88 | | -// typeof a will be Ref<{ a: number } | null> |
89 | | -export function ref<T = null>(raw: null): Ref<T | null>; |
90 | | -// with init value: a = ref({ a: ref(0) }) |
91 | | -// typeof a will be Ref<{ a: number }> |
92 | | -export function ref<S, T = unknown, R = HasDefined<S> extends true ? S : RefValue<T>>( |
93 | | - raw: T |
94 | | -): Ref<R>; |
95 | | -// implementation |
96 | | -export function ref(raw?: any): any { |
97 | | - // if (isRef(raw)) { |
98 | | - // return {} as any; |
99 | | - // } |
| 84 | +export function ref(raw?: unknown) { |
100 | 85 | if (isRef(raw)) { |
101 | 86 | return raw; |
102 | 87 | } |
|
0 commit comments