From c518517cb324eb29a89ed29f2f92170a017789bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9C=E6=96=B9os?= Date: Thu, 5 Sep 2024 16:09:10 +0800 Subject: [PATCH 1/2] chore(types): removed the Awaited compatibility type tool (#11820) --- packages/runtime-core/src/scheduler.ts | 2 +- packages/shared/src/typeUtils.ts | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index 7f52a77bd50..727eb14e310 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -1,5 +1,5 @@ import { ErrorCodes, callWithErrorHandling, handleError } from './errorHandling' -import { type Awaited, NOOP, isArray } from '@vue/shared' +import { NOOP, isArray } from '@vue/shared' import { type ComponentInternalInstance, getComponentName } from './component' export enum SchedulerJobFlags { diff --git a/packages/shared/src/typeUtils.ts b/packages/shared/src/typeUtils.ts index 4846751b84e..1fd161ceb05 100644 --- a/packages/shared/src/typeUtils.ts +++ b/packages/shared/src/typeUtils.ts @@ -13,15 +13,6 @@ export type LooseRequired = { [P in keyof (T & Required)]: T[P] } // https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360 export type IfAny = 0 extends 1 & T ? Y : N -// To prevent users with TypeScript versions lower than 4.5 from encountering unsupported Awaited type, a copy has been made here. -export type Awaited = T extends null | undefined - ? T // special case for `null | undefined` when not in `--strictNullChecks` mode - : T extends object & { then(onfulfilled: infer F, ...args: infer _): any } // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped - ? F extends (value: infer V, ...args: infer _) => any // if the argument to `then` is callable, extracts the first argument - ? Awaited // recursively unwrap the value - : never // the argument to `then` was not callable - : T // non-object or non-thenable - /** * Utility for extracting the parameters from a function overload (for typed emits) * https://github.com/microsoft/TypeScript/issues/32164#issuecomment-1146737709 From 98864a7ef5c8080c407166c8221488a4eacbbc81 Mon Sep 17 00:00:00 2001 From: yangxiuxiu <79584569+yangxiuxiu1115@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:10:37 +0800 Subject: [PATCH 2/2] fix(reactivity): pass oldValue to computed getter (#11813) close #11812 --- packages/reactivity/__tests__/computed.spec.ts | 14 ++++++++++++++ packages/reactivity/src/effect.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/reactivity/__tests__/computed.spec.ts b/packages/reactivity/__tests__/computed.spec.ts index 08b034f79f1..c3409eee77e 100644 --- a/packages/reactivity/__tests__/computed.spec.ts +++ b/packages/reactivity/__tests__/computed.spec.ts @@ -33,6 +33,20 @@ describe('reactivity/computed', () => { expect(cValue.value).toBe(1) }) + it('pass oldValue to computed getter', () => { + const count = ref(0) + const oldValue = ref() + const curValue = computed(pre => { + oldValue.value = pre + return count.value + }) + expect(curValue.value).toBe(0) + expect(oldValue.value).toBe(undefined) + count.value++ + expect(curValue.value).toBe(1) + expect(oldValue.value).toBe(0) + }) + it('should compute lazily', () => { const value = reactive<{ foo?: number }>({}) const getter = vi.fn(() => value.foo) diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index a22990f6729..88493e4e9a9 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -381,7 +381,7 @@ export function refreshComputed(computed: ComputedRefImpl): false | undefined { try { prepareDeps(computed) - const value = computed.fn() + const value = computed.fn(computed._value) if (dep.version === 0 || hasChanged(value, computed._value)) { computed._value = value dep.version++