Skip to content

Commit 2b588cf

Browse files
authored
fix(types): unwrap refs on public instance data (#3319)
fix #3315
1 parent 44166b4 commit 2b588cf

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

packages/reactivity/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export {
2525
markRaw,
2626
toRaw,
2727
ReactiveFlags,
28-
DeepReadonly
28+
DeepReadonly,
29+
UnwrapNestedRefs
2930
} from './reactive'
3031
export {
3132
computed,

packages/reactivity/src/reactive.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function getTargetType(value: Target) {
5757
}
5858

5959
// only unwrap nested ref
60-
type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
60+
export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
6161

6262
/**
6363
* Creates a reactive copy of the original object.

packages/runtime-core/src/componentPublicInstance.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
ReactiveFlags,
2121
track,
2222
TrackOpTypes,
23-
ShallowUnwrapRef
23+
ShallowUnwrapRef,
24+
UnwrapNestedRefs
2425
} from '@vue/reactivity'
2526
import {
2627
ExtractComputedReturns,
@@ -195,7 +196,7 @@ export type ComponentPublicInstance<
195196
): WatchStopHandle
196197
} & P &
197198
ShallowUnwrapRef<B> &
198-
D &
199+
UnwrapNestedRefs<D> &
199200
ExtractComputedReturns<C> &
200201
M &
201202
ComponentCustomProperties

test-dts/defineComponent.test-d.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ describe('type inference w/ options API', () => {
379379
// here in data() - somehow that would mess up the inference
380380
expectType<number | undefined>(this.a)
381381
return {
382-
c: this.a || 123
382+
c: this.a || 123,
383+
someRef: ref(0)
383384
}
384385
},
385386
computed: {
@@ -418,6 +419,7 @@ describe('type inference w/ options API', () => {
418419
expectType<number>(this.d)
419420
// computed get/set
420421
expectType<number>(this.e)
422+
expectType<number>(this.someRef)
421423
},
422424
methods: {
423425
doSomething() {

0 commit comments

Comments
 (0)