Skip to content

Commit

Permalink
fix(types): unwrap refs on public instance data (#3319)
Browse files Browse the repository at this point in the history
fix #3315
  • Loading branch information
HcySunYang authored Mar 25, 2021
1 parent 44166b4 commit 2b588cf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/reactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export {
markRaw,
toRaw,
ReactiveFlags,
DeepReadonly
DeepReadonly,
UnwrapNestedRefs
} from './reactive'
export {
computed,
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/src/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getTargetType(value: Target) {
}

// only unwrap nested ref
type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>

/**
* Creates a reactive copy of the original object.
Expand Down
5 changes: 3 additions & 2 deletions packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
ReactiveFlags,
track,
TrackOpTypes,
ShallowUnwrapRef
ShallowUnwrapRef,
UnwrapNestedRefs
} from '@vue/reactivity'
import {
ExtractComputedReturns,
Expand Down Expand Up @@ -195,7 +196,7 @@ export type ComponentPublicInstance<
): WatchStopHandle
} & P &
ShallowUnwrapRef<B> &
D &
UnwrapNestedRefs<D> &
ExtractComputedReturns<C> &
M &
ComponentCustomProperties
Expand Down
4 changes: 3 additions & 1 deletion test-dts/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ describe('type inference w/ options API', () => {
// here in data() - somehow that would mess up the inference
expectType<number | undefined>(this.a)
return {
c: this.a || 123
c: this.a || 123,
someRef: ref(0)
}
},
computed: {
Expand Down Expand Up @@ -418,6 +419,7 @@ describe('type inference w/ options API', () => {
expectType<number>(this.d)
// computed get/set
expectType<number>(this.e)
expectType<number>(this.someRef)
},
methods: {
doSomething() {
Expand Down

0 comments on commit 2b588cf

Please sign in to comment.