From: Evan You Date: Wed, 7 Aug 2024 10:12:07 +0000 (+0800) Subject: fix: Revert "fix(types/ref): allow getter and setter types to be unrelated (#11442)" X-Git-Tag: v3.4.37~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b1abac06cdb198bd72f8e614b1f68b92e1c78339;p=thirdparty%2Fvuejs%2Fcore.git 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. --- diff --git a/packages/dts-test/ref.test-d.ts b/packages/dts-test/ref.test-d.ts index 46d39214b9..1456c52323 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 6c8576f0c6..45c898ef67 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 6e22d1bcd5..3e9b05062f 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 8b570bc28f..cdf8b8c888 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,