Skip to content

Commit 70452af

Browse files
authored
fix(type): fix incorrect ref unwrap (#344)
* fix(type): fix incorrect ref unwrap, resolve #257 * fix type * exact matched to vue-next
1 parent b090c2c commit 70452af

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/reactivity/ref.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Data } from '../component';
22
import { RefKey } from '../symbols';
33
import { proxy, isPlainObject, warn } from '../utils';
4-
import { HasDefined } from '../types/basic';
54
import { reactive, isReactive, shallowReactive } from './reactive';
65
import { ComputedRef } from '../apis/computed';
76

@@ -79,24 +78,10 @@ export function createRef<T>(options: RefOption<T>) {
7978
return Object.seal(new RefImpl<T>(options));
8079
}
8180

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>>;
8683
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) {
10085
if (isRef(raw)) {
10186
return raw;
10287
}

0 commit comments

Comments
 (0)