parent
8d817bb446
commit
a840e7ddf0
@ -8,7 +8,13 @@ import {
|
|||||||
ComputedOptions,
|
ComputedOptions,
|
||||||
MethodOptions
|
MethodOptions
|
||||||
} from './apiOptions'
|
} from './apiOptions'
|
||||||
import { UnwrapRef, ReactiveEffect, isRef, isReactive } from '@vue/reactivity'
|
import {
|
||||||
|
ReactiveEffect,
|
||||||
|
isRef,
|
||||||
|
isReactive,
|
||||||
|
Ref,
|
||||||
|
ComputedRef
|
||||||
|
} from '@vue/reactivity'
|
||||||
import { warn } from './warning'
|
import { warn } from './warning'
|
||||||
import { Slots } from './componentSlots'
|
import { Slots } from './componentSlots'
|
||||||
import {
|
import {
|
||||||
@ -19,9 +25,9 @@ import {
|
|||||||
// public properties exposed on the proxy, which is used as the render context
|
// public properties exposed on the proxy, which is used as the render context
|
||||||
// in templates (as `this` in the render option)
|
// in templates (as `this` in the render option)
|
||||||
export type ComponentPublicInstance<
|
export type ComponentPublicInstance<
|
||||||
P = {},
|
P = {}, // props type extracted from props option
|
||||||
B = {},
|
B = {}, // raw bindings returned from setup()
|
||||||
D = {},
|
D = {}, // return from data()
|
||||||
C extends ComputedOptions = {},
|
C extends ComputedOptions = {},
|
||||||
M extends MethodOptions = {},
|
M extends MethodOptions = {},
|
||||||
PublicProps = P
|
PublicProps = P
|
||||||
@ -40,11 +46,17 @@ export type ComponentPublicInstance<
|
|||||||
$nextTick: typeof nextTick
|
$nextTick: typeof nextTick
|
||||||
$watch: typeof instanceWatch
|
$watch: typeof instanceWatch
|
||||||
} & P &
|
} & P &
|
||||||
UnwrapRef<B> &
|
UnwrapSetupBindings<B> &
|
||||||
D &
|
D &
|
||||||
ExtractComputedReturns<C> &
|
ExtractComputedReturns<C> &
|
||||||
M
|
M
|
||||||
|
|
||||||
|
type UnwrapSetupBindings<B> = { [K in keyof B]: UnwrapBinding<B[K]> }
|
||||||
|
|
||||||
|
type UnwrapBinding<B> = B extends ComputedRef<any>
|
||||||
|
? B extends ComputedRef<infer V> ? V : B
|
||||||
|
: B extends Ref<infer V> ? V : B
|
||||||
|
|
||||||
const publicPropertiesMap: Record<
|
const publicPropertiesMap: Record<
|
||||||
string,
|
string,
|
||||||
(i: ComponentInternalInstance) => any
|
(i: ComponentInternalInstance) => any
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
import { expectError, expectType } from 'tsd'
|
import { expectError, expectType } from 'tsd'
|
||||||
import { describe, defineComponent, PropType, ref, createApp } from './index'
|
import {
|
||||||
|
describe,
|
||||||
|
defineComponent,
|
||||||
|
PropType,
|
||||||
|
ref,
|
||||||
|
Ref,
|
||||||
|
reactive,
|
||||||
|
createApp
|
||||||
|
} from './index'
|
||||||
|
|
||||||
describe('with object props', () => {
|
describe('with object props', () => {
|
||||||
interface ExpectedProps {
|
interface ExpectedProps {
|
||||||
@ -57,11 +65,14 @@ describe('with object props', () => {
|
|||||||
// setup context
|
// setup context
|
||||||
return {
|
return {
|
||||||
c: ref(1),
|
c: ref(1),
|
||||||
d: {
|
d: reactive({
|
||||||
e: ref('hi')
|
e: ref('hi')
|
||||||
},
|
}),
|
||||||
f: {
|
f: reactive({
|
||||||
g: ref('hello' as GT)
|
g: ref('hello' as GT)
|
||||||
|
}),
|
||||||
|
h: {
|
||||||
|
i: ref('hi')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -95,6 +106,9 @@ describe('with object props', () => {
|
|||||||
expectType<string>(this.d.e)
|
expectType<string>(this.d.e)
|
||||||
expectType<GT>(this.f.g)
|
expectType<GT>(this.f.g)
|
||||||
|
|
||||||
|
// should not unwrap refs nested under non-reactive objects
|
||||||
|
expectType<Ref<string>>(this.h.i)
|
||||||
|
|
||||||
// setup context properties should be mutable
|
// setup context properties should be mutable
|
||||||
this.c = 2
|
this.c = 2
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user