Skip to content

types: the data type of the public instance should be unwrapped #3319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -197,7 +198,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 @@ -341,7 +341,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 @@ -380,6 +381,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