|
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,26 +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 |
| -export function ref<T extends object>(value: T): T extends Ref ? T : Ref<UnwrapRef<T>>; |
85 |
| -export function ref<T>(value: T): Ref<UnwrapRef<T>>; |
86 |
| -// without init value, explicit typed: a = ref<{ a: number }>() |
87 |
| -// 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>>; |
88 | 83 | export function ref<T = any>(): Ref<T | undefined>;
|
89 |
| -// with null as init value: a = ref<{ a: number }>(null); |
90 |
| -// typeof a will be Ref<{ a: number } | null> |
91 |
| -export function ref<T = null>(raw: null): Ref<T | null>; |
92 |
| -// with init value: a = ref({ a: ref(0) }) |
93 |
| -// typeof a will be Ref<{ a: number }> |
94 |
| -export function ref<S, T = unknown, R = HasDefined<S> extends true ? S : RefValue<T>>( |
95 |
| - raw: T |
96 |
| -): Ref<R>; |
97 |
| -// implementation |
98 |
| -export function ref(raw?: any): any { |
99 |
| - // if (isRef(raw)) { |
100 |
| - // return {} as any; |
101 |
| - // } |
| 84 | +export function ref(raw?: unknown) { |
102 | 85 | if (isRef(raw)) {
|
103 | 86 | return raw;
|
104 | 87 | }
|
|
0 commit comments