Skip to content

Commit 3b73568

Browse files
committed
chore: update
1 parent 6175e41 commit 3b73568

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

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

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

613613
const vm = {} as InstanceType<typeof Comp>
614-
if (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.exposeProxy.a = 2
622-
}
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
623621
})
624622

625623
// #5948
@@ -796,7 +794,7 @@ describe('function syntax w/ expose', () => {
796794
},
797795
)
798796
const foo = new Foo()
799-
expectType<string>(foo.exposeProxy!.msg)
797+
expectType<string>(foo.exposeProxy.msg)
800798

801799
// runtime
802800
const Bar = defineVaporComponent(
@@ -808,7 +806,7 @@ describe('function syntax w/ expose', () => {
808806
},
809807
)
810808
const bar = new Bar()
811-
expectType<string>(bar.exposeProxy!.msg)
809+
expectType<string>(bar.exposeProxy.msg)
812810
})
813811

814812
describe('function syntax w/ runtime props', () => {
@@ -1015,26 +1013,26 @@ describe('should work when props type is incompatible with setup returned type '
10151013
expectType<
10161014
VaporComponentInstance<{ size: SizeType }, {}, {}, { size: number }>
10171015
>(CompA)
1018-
expectType<number>(CompA.exposeProxy!.size)
1016+
expectType<number>(CompA.exposeProxy.size)
10191017
expectType<SizeType>(CompA.props.size)
10201018
})
10211019

10221020
describe('expose typing', () => {
10231021
// types
1024-
const Foo = defineVaporComponent({
1025-
setup(
1022+
const Foo = defineVaporComponent(
1023+
(
10261024
props: { some?: string },
10271025
{ expose }: { expose: (exposed: { a: number; b: string }) => void },
1028-
) {
1026+
) => {
10291027
expose({ a: 1, b: '' })
10301028
},
1031-
})
1029+
)
10321030
const foo = new Foo()
10331031
// internal should still be exposed
10341032
foo.props
10351033

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

10391037
// runtime
10401038
const Bar = defineVaporComponent({
@@ -1050,8 +1048,8 @@ describe('expose typing', () => {
10501048
// internal should still be exposed
10511049
bar.props
10521050

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

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

packages/runtime-vapor/src/apiDefineComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function defineVaporComponent<
114114
attrs: Record<string, any>
115115
expose: (exposed: Exposed) => void
116116
},
117-
) => RenderReturn<TypeBlock>,
117+
) => RenderReturn<TypeBlock> | void,
118118
extraOptions?: ObjectVaporComponent<
119119
(keyof Props)[],
120120
Emits,
@@ -140,7 +140,7 @@ export function defineVaporComponent<
140140
attrs: Record<string, any>
141141
expose: (exposed: Exposed) => void
142142
},
143-
) => RenderReturn<TypeBlock>,
143+
) => RenderReturn<TypeBlock> | void,
144144
extraOptions?: ObjectVaporComponent<
145145
ComponentObjectPropsOptions<Props>,
146146
Emits,

packages/runtime-vapor/src/component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export interface ObjectVaporComponent<
119119
emit: EmitFn<Emits>,
120120
attrs: any,
121121
slots: Slots,
122-
): RenderReturn<TypeBlock>
122+
): RenderReturn<TypeBlock> | void
123123

124124
name?: string
125125
vapor?: boolean
@@ -397,8 +397,10 @@ export class VaporComponentInstance<
397397
expose: (<T extends Record<string, any> = Exposed>(exposed: T) => void) &
398398
// compatible with vdom components
399399
string[]
400-
exposed: Exposed | null
401-
exposeProxy: ShallowUnwrapRef<Exposed> | null
400+
exposed: Record<string, any> extends Exposed ? Exposed | null : Exposed
401+
exposeProxy: Record<string, any> extends Exposed
402+
? Exposed | null
403+
: ShallowUnwrapRef<Exposed>
402404

403405
// for useTemplateRef()
404406
refs: TypeRefs
@@ -474,7 +476,7 @@ export class VaporComponentInstance<
474476
this.exposeProxy =
475477
this.propsDefaults =
476478
this.suspense =
477-
null
479+
null as any
478480

479481
this.isMounted =
480482
this.isUnmounted =

0 commit comments

Comments
 (0)