|
1 | 1 | import { Data } from '../component';
|
2 | 2 | import { RefKey } from '../symbols';
|
3 | 3 | import { proxy, isPlainObject } from '../utils';
|
| 4 | +import { HasDefined } from '../types/basic'; |
4 | 5 | import { reactive } from './reactive';
|
5 | 6 |
|
6 | 7 | type BailTypes = Function | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any>;
|
@@ -106,12 +107,14 @@ type RefValue<T> = T extends Ref<infer V> ? V : UnwrapRef<T>;
|
106 | 107 | // without init value, explicit typed: a = ref<{ a: number }>()
|
107 | 108 | // typeof a will be Ref<{ a: number } | undefined>
|
108 | 109 | export function ref<T = undefined>(): Ref<T | undefined>;
|
109 |
| -// with init value: a = ref({ a: ref(0) }) |
110 |
| -// typeof a will be Ref<{ a: number }> |
111 |
| -export function ref<T, R = RefValue<T>>(raw: T): Ref<R>; |
112 | 110 | // with null as init value: a = ref<{ a: number }>(null);
|
113 | 111 | // typeof a will be Ref<{ a: number } | null>
|
114 |
| -export function ref<T, R = RefValue<T>>(raw: T | null): Ref<R | null>; |
| 112 | +export function ref<T = null>(raw: null): Ref<T | null>; |
| 113 | +// with init value: a = ref({ a: ref(0) }) |
| 114 | +// typeof a will be Ref<{ a: number }> |
| 115 | +export function ref<S, T = unknown, R = HasDefined<S> extends true ? S : RefValue<T>>( |
| 116 | + raw: T |
| 117 | +): Ref<R>; |
115 | 118 | // implementation
|
116 | 119 | export function ref(raw?: any): any {
|
117 | 120 | // if (isRef(raw)) {
|
|
0 commit comments