From 58638a5067d78165432c9c459f2e787951923de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=A9vesque?= Date: Tue, 7 Mar 2023 18:42:06 -0500 Subject: [PATCH 1/3] Fixes shallowRef's return type --- src/v3/reactivity/ref.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v3/reactivity/ref.ts b/src/v3/reactivity/ref.ts index 244acc9b0d4..1a086bd2998 100644 --- a/src/v3/reactivity/ref.ts +++ b/src/v3/reactivity/ref.ts @@ -55,7 +55,7 @@ export type ShallowRef = Ref & { [ShallowRefMarker]?: true } export function shallowRef( value: T -): T extends Ref ? T : ShallowRef +): [T] extends [Ref] ? T : ShallowRef export function shallowRef(value: T): ShallowRef export function shallowRef(): ShallowRef export function shallowRef(value?: unknown) { From 1de486c741d2079c1fd0a2e59631be7275aca1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=A9vesque?= Date: Thu, 9 Mar 2023 18:59:02 -0500 Subject: [PATCH 2/3] chore: dts-test #12978 --- types/test/v3/reactivity-test.ts | 13 ++++++++++++- types/test/v3/watch-test.ts | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/types/test/v3/reactivity-test.ts b/types/test/v3/reactivity-test.ts index dd1b2a4d8b6..c357bf8d5c7 100644 --- a/types/test/v3/reactivity-test.ts +++ b/types/test/v3/reactivity-test.ts @@ -15,7 +15,7 @@ import { set, del } from '../../index' -import { describe, expectType } from '../utils' +import { IsUnion, describe, expectType } from '../utils' function plainType(arg: number | Ref) { // ref coercing @@ -385,3 +385,14 @@ describe('set/del', () => { // @ts-expect-error del([], 'fse', 123) }) + + +{ + //#12978 + type Steps = { step: '1' } | { step: '2' } + const shallowUnionGenParam = shallowRef({ step: '1' }) + const shallowUnionAsCast = shallowRef({ step: '1' } as Steps) + + expectType>(false) + expectType>(false) +} \ No newline at end of file diff --git a/types/test/v3/watch-test.ts b/types/test/v3/watch-test.ts index 388fdc2ad9e..aeb5ff36c36 100644 --- a/types/test/v3/watch-test.ts +++ b/types/test/v3/watch-test.ts @@ -1,4 +1,4 @@ -import { ref, computed, watch } from '../../index' +import { ref, computed, watch, shallowRef } from '../../index' import { expectType } from '../utils' const source = ref('foo') @@ -76,3 +76,17 @@ watch([someRef, otherRef], values => { // no type error console.log(value2.a) }) + +{ + //#12978 + type Steps = { step: '1' } | { step: '2' } + const shallowUnionGenParam = shallowRef({ step: '1' }) + const shallowUnionAsCast = shallowRef({ step: '1' } as Steps) + + watch(shallowUnionGenParam, value => { + expectType(value) + }) + watch(shallowUnionAsCast, value => { + expectType(value) + }) +} \ No newline at end of file From a987bc1b98281d3fd37d7a879aac1202d9dfa652 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 6 Dec 2023 23:50:08 +0800 Subject: [PATCH 3/3] Update ref.ts --- src/v3/reactivity/ref.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/v3/reactivity/ref.ts b/src/v3/reactivity/ref.ts index 1a086bd2998..33495806da1 100644 --- a/src/v3/reactivity/ref.ts +++ b/src/v3/reactivity/ref.ts @@ -40,9 +40,7 @@ export function isRef(r: any): r is Ref { return !!(r && (r as Ref).__v_isRef === true) } -export function ref( - value: T -): [T] extends [Ref] ? T : Ref> +export function ref(value: T): T export function ref(value: T): Ref> export function ref(): Ref export function ref(value?: unknown) { @@ -53,9 +51,8 @@ declare const ShallowRefMarker: unique symbol export type ShallowRef = Ref & { [ShallowRefMarker]?: true } -export function shallowRef( - value: T -): [T] extends [Ref] ? T : ShallowRef +export function shallowRef(value: T | Ref): Ref | ShallowRef +export function shallowRef(value: T): T export function shallowRef(value: T): ShallowRef export function shallowRef(): ShallowRef export function shallowRef(value?: unknown) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy