Skip to content

Commit bd21aee

Browse files
committed
chore: add null for exposedProxy
1 parent cb19c09 commit bd21aee

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

packages-private/dts-test/defineVaporComponent.test-d.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,15 @@ describe('async setup', () => {
611611
})
612612

613613
const vm = {} as InstanceType<typeof Comp>
614-
// assert setup context unwrapping
615-
expectType<number>(vm.exposeProxy.a)
616-
expectType<string>(vm.exposeProxy.b.c.value)
617-
expectType<GT>(vm.exposeProxy.d.e)
618-
619-
// setup context properties should be mutable
620-
vm.exposeProxy.a = 2
614+
if (vm.exposed && vm.exposeProxy) {
615+
// assert setup context unwrapping
616+
expectType<number>(vm.exposeProxy.a)
617+
expectType<string>(vm.exposeProxy.b.c.value)
618+
expectType<GT>(vm.exposeProxy.d.e)
619+
620+
// setup context properties should be mutable
621+
vm.exposed.a.value = 2
622+
}
621623
})
622624

623625
// #5948
@@ -794,7 +796,7 @@ describe('function syntax w/ expose', () => {
794796
},
795797
)
796798
const foo = new Foo()
797-
expectType<string>(foo.exposeProxy.msg)
799+
expectType<string>(foo.exposeProxy!.msg)
798800

799801
// runtime
800802
const Bar = defineVaporComponent(
@@ -806,7 +808,7 @@ describe('function syntax w/ expose', () => {
806808
},
807809
)
808810
const bar = new Bar()
809-
expectType<string>(bar.exposeProxy.msg)
811+
expectType<string>(bar.exposeProxy!.msg)
810812
})
811813

812814
describe('function syntax w/ runtime props', () => {
@@ -1013,7 +1015,7 @@ describe('should work when props type is incompatible with setup returned type '
10131015
expectType<
10141016
VaporComponentInstance<{ size: SizeType }, {}, {}, { size: number }>
10151017
>(CompA)
1016-
expectType<number>(CompA.exposeProxy.size)
1018+
expectType<number>(CompA.exposeProxy!.size)
10171019
expectType<SizeType>(CompA.props.size)
10181020
})
10191021

@@ -1031,8 +1033,8 @@ describe('expose typing', () => {
10311033
// internal should still be exposed
10321034
foo.props
10331035

1034-
expectType<number>(foo.exposeProxy.a)
1035-
expectType<string>(foo.exposeProxy.b)
1036+
expectType<number>(foo.exposeProxy!.a)
1037+
expectType<string>(foo.exposeProxy!.b)
10361038

10371039
// runtime
10381040
const Bar = defineVaporComponent({
@@ -1048,8 +1050,8 @@ describe('expose typing', () => {
10481050
// internal should still be exposed
10491051
bar.props
10501052

1051-
expectType<number>(bar.exposeProxy.a)
1052-
expectType<string>(bar.exposeProxy.b)
1053+
expectType<number>(bar.exposeProxy!.a)
1054+
expectType<string>(bar.exposeProxy!.b)
10531055
})
10541056

10551057
// code generated by tsc / vue-tsc, make sure this continues to work

packages/runtime-vapor/src/component.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,8 @@ export class VaporComponentInstance<
397397
expose: (<T extends Record<string, any> = Exposed>(exposed: T) => void) &
398398
// compatible with vdom components
399399
string[]
400-
exposed: Record<string, any> extends Exposed ? Exposed | null : Exposed
401-
exposeProxy: Record<string, any> extends Exposed
402-
? Exposed | null
403-
: ShallowUnwrapRef<Exposed>
400+
exposed: Exposed | null
401+
exposeProxy: ShallowUnwrapRef<Exposed> | null
404402

405403
// for useTemplateRef()
406404
refs: TypeRefs
@@ -476,7 +474,7 @@ export class VaporComponentInstance<
476474
this.exposeProxy =
477475
this.propsDefaults =
478476
this.suspense =
479-
null as any
477+
null
480478

481479
this.isMounted =
482480
this.isUnmounted =

0 commit comments

Comments
 (0)