Skip to content

Commit 20aa749

Browse files
Doctor-wusxzz
authored andcommitted
feat(runtime-vapor): add setup ctx type
1 parent 9d8c1e5 commit 20aa749

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packages/runtime-vapor/src/apiSetup.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { proxyRefs } from '@vue/reactivity'
2-
import { isArray, isFunction, isObject } from '@vue/shared'
2+
import { type Data, isArray, isFunction, isObject } from '@vue/shared'
33
import { type ComponentInternalInstance, setCurrentInstance } from './component'
44
import { getAttrsProxy } from './componentAttrs'
5-
// import { SetupContext } from 'vue'
65
import { type Block, fragmentKey } from './apiRender'
6+
import type { EmitFn, EmitsOptions } from './componentEmits'
7+
8+
export type SetupContext<E = EmitsOptions> = E extends any
9+
? {
10+
attrs: Data
11+
emit: EmitFn<E>
12+
expose: (exposed?: Record<string, any>) => void
13+
}
14+
: never
715

816
export function setupComponent(instance: ComponentInternalInstance): void {
917
const reset = setCurrentInstance(instance)
@@ -42,7 +50,9 @@ export function setupComponent(instance: ComponentInternalInstance): void {
4250
reset()
4351
}
4452

45-
export function createSetupContext(instance: ComponentInternalInstance): any {
53+
export function createSetupContext(
54+
instance: ComponentInternalInstance,
55+
): SetupContext {
4656
if (__DEV__) {
4757
// We use getters in dev in case libs like test-utils overwrite instance
4858
// properties (overwrites should not be done in prod)
@@ -57,6 +67,7 @@ export function createSetupContext(instance: ComponentInternalInstance): any {
5767
})
5868
} else {
5969
return {
70+
expose: () => {},
6071
get attrs() {
6172
return getAttrsProxy(instance)
6273
},

0 commit comments

Comments
 (0)