Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/vuePublic

Commita174c29

Browse files
authored
fix(types): fix shallowRef's return type (#12979)
close#12978
1 parentf5ef882 commita174c29

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

‎src/v3/reactivity/ref.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ export function isRef(r: any): r is Ref {
4040
return!!(r&&(rasRef).__v_isRef===true)
4141
}
4242

43-
exportfunctionref<Textendsobject>(
44-
value:T
45-
):[T]extends[Ref] ?T :Ref<UnwrapRef<T>>
43+
exportfunctionref<TextendsRef>(value:T):T
4644
exportfunctionref<T>(value:T):Ref<UnwrapRef<T>>
4745
exportfunctionref<T=any>():Ref<T|undefined>
4846
exportfunctionref(value?:unknown){
@@ -53,9 +51,8 @@ declare const ShallowRefMarker: unique symbol
5351

5452
exporttypeShallowRef<T=any>=Ref<T>&{[ShallowRefMarker]?:true}
5553

56-
exportfunctionshallowRef<Textendsobject>(
57-
value:T
58-
):TextendsRef ?T :ShallowRef<T>
54+
exportfunctionshallowRef<T>(value:T|Ref<T>):Ref<T>|ShallowRef<T>
55+
exportfunctionshallowRef<TextendsRef>(value:T):T
5956
exportfunctionshallowRef<T>(value:T):ShallowRef<T>
6057
exportfunctionshallowRef<T=any>():ShallowRef<T|undefined>
6158
exportfunctionshallowRef(value?:unknown){

‎types/test/v3/reactivity-test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
set,
1616
del
1717
}from'../../index'
18-
import{describe,expectType}from'../utils'
18+
import{IsUnion,describe,expectType}from'../utils'
1919

2020
functionplainType(arg:number|Ref<number>){
2121
// ref coercing
@@ -385,3 +385,14 @@ describe('set/del', () => {
385385
//@ts-expect-error
386386
del([],'fse',123)
387387
})
388+
389+
390+
{
391+
//#12978
392+
typeSteps={step:'1'}|{step:'2'}
393+
constshallowUnionGenParam=shallowRef<Steps>({step:'1'})
394+
constshallowUnionAsCast=shallowRef({step:'1'}asSteps)
395+
396+
expectType<IsUnion<typeofshallowUnionGenParam>>(false)
397+
expectType<IsUnion<typeofshallowUnionAsCast>>(false)
398+
}

‎types/test/v3/watch-test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{ref,computed,watch}from'../../index'
1+
import{ref,computed,watch,shallowRef}from'../../index'
22
import{expectType}from'../utils'
33

44
constsource=ref('foo')
@@ -76,3 +76,17 @@ watch([someRef, otherRef], values => {
7676
// no type error
7777
console.log(value2.a)
7878
})
79+
80+
{
81+
//#12978
82+
typeSteps={step:'1'}|{step:'2'}
83+
constshallowUnionGenParam=shallowRef<Steps>({step:'1'})
84+
constshallowUnionAsCast=shallowRef({step:'1'}asSteps)
85+
86+
watch(shallowUnionGenParam,value=>{
87+
expectType<Steps>(value)
88+
})
89+
watch(shallowUnionAsCast,value=>{
90+
expectType<Steps>(value)
91+
})
92+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp