From b1abac06cdb198bd72f8e614b1f68b92e1c78339 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 7 Aug 2024 18:12:07 +0800 Subject: [PATCH] fix: Revert "fix(types/ref): allow getter and setter types to be unrelated (#11442)" This reverts commit e0b2975ef65ae6a0be0aa0a0df43fb887c665251. This change requires TypeScript 5.1 so it is moved to a minor release. --- packages/dts-test/ref.test-d.ts | 10 ---------- packages/dts-test/watch.test-d.ts | 8 -------- packages/reactivity/src/ref.ts | 7 +++---- packages/runtime-core/src/apiWatch.ts | 2 +- 4 files changed, 4 insertions(+), 23 deletions(-) diff --git a/packages/dts-test/ref.test-d.ts b/packages/dts-test/ref.test-d.ts index 46d39214b93..1456c523239 100644 --- a/packages/dts-test/ref.test-d.ts +++ b/packages/dts-test/ref.test-d.ts @@ -172,16 +172,6 @@ describe('ref with generic', () => { expectType(ss.value.name) }) -describe('allow getter and setter types to be unrelated', () => { - const a = { b: ref(0) } - const c = ref(a) - c.value = a - - const d = {} as T - const e = ref(d) - e.value = d -}) - // shallowRef type Status = 'initial' | 'ready' | 'invalidating' const shallowStatus = shallowRef('initial') diff --git a/packages/dts-test/watch.test-d.ts b/packages/dts-test/watch.test-d.ts index 6c8576f0c6b..45c898ef672 100644 --- a/packages/dts-test/watch.test-d.ts +++ b/packages/dts-test/watch.test-d.ts @@ -1,6 +1,5 @@ import { type ComputedRef, - type MaybeRef, type Ref, computed, defineComponent, @@ -204,10 +203,3 @@ defineComponent({ expectType<{ foo: string }>(value) }) } - -{ - const css: MaybeRef = '' - watch(ref(css), value => { - expectType(value) - }) -} diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 6e22d1bcd58..3e9b05062f3 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -30,9 +30,8 @@ import { warn } from './warning' declare const RefSymbol: unique symbol export declare const RawSymbol: unique symbol -export interface Ref { - get value(): T - set value(_: S) +export interface Ref { + value: T /** * Type differentiator only. * We need this to be in public d.ts but don't want it to show up in IDE @@ -109,7 +108,7 @@ export function isRef(r: any): r is Ref { * @param value - The object to wrap in the ref. * @see {@link https://vuejs.org/api/reactivity-core.html#ref} */ -export function ref(value: T): Ref, UnwrapRef | T> +export function ref(value: T): Ref> export function ref(): Ref export function ref(value?: unknown) { return createRef(value, false) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 8b570bc28fa..cdf8b8c888f 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -46,7 +46,7 @@ import { useSSRContext } from './helpers/useSsrContext' export type WatchEffect = (onCleanup: OnCleanup) => void -export type WatchSource = Ref | ComputedRef | (() => T) +export type WatchSource = Ref | ComputedRef | (() => T) export type WatchCallback = ( value: V,