Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions src/reactivity/ref.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Data } from '../component';
import { RefKey } from '../symbols';
import { proxy, isPlainObject, warn } from '../utils';
import { HasDefined } from '../types/basic';
import { reactive, isReactive, shallowReactive } from './reactive';
import { ComputedRef } from '../apis/computed';

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

type RefValue<T> = T extends Ref<infer V> ? V : UnwrapRef<T>;

// without init value, explicit typed: a = ref<{ a: number }>()
// typeof a will be Ref<{ a: number } | undefined>
export function ref<T extends object>(raw: T): T extends Ref ? T : Ref<UnwrapRef<T>>;
export function ref<T>(raw: T): Ref<UnwrapRef<T>>;
export function ref<T = any>(): Ref<T | undefined>;
// with null as init value: a = ref<{ a: number }>(null);
// typeof a will be Ref<{ a: number } | null>
export function ref<T = null>(raw: null): Ref<T | null>;
// with init value: a = ref({ a: ref(0) })
// typeof a will be Ref<{ a: number }>
export function ref<S, T = unknown, R = HasDefined<S> extends true ? S : RefValue<T>>(
raw: T
): Ref<R>;
// implementation
export function ref(raw?: any): any {
// if (isRef(raw)) {
// return {} as any;
// }
export function ref(raw?: unknown) {
if (isRef(raw)) {
return raw;
}
Expand Down