Skip to content
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

fix(runtime-core): force evalutating SetupContext type (fix #2362) #2818

Merged
merged 2 commits into from
Nov 14, 2022
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
15 changes: 9 additions & 6 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,15 @@ export const enum LifecycleHooks {
SERVER_PREFETCH = 'sp'
}

export interface SetupContext<E = EmitsOptions> {
attrs: Data
slots: Slots
emit: EmitFn<E>
expose: (exposed?: Record<string, any>) => void
}
// use `E extends any` to force evaluating type to fix #2362
export type SetupContext<E = EmitsOptions> = E extends any
? {
attrs: Data
slots: Slots
emit: EmitFn<E>
expose: (exposed?: Record<string, any>) => void
}
: never

/**
* @internal
Expand Down
12 changes: 11 additions & 1 deletion test-dts/component.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
FunctionalComponent,
ComponentPublicInstance,
toRefs,
IsAny
IsAny,
SetupContext,
expectAssignable
} from './index'

declare function extractComponentOptions<Props, RawBindings>(
Expand Down Expand Up @@ -476,3 +478,11 @@ describe('class', () => {

expectType<number>(props.foo)
})

describe('SetupContext', () => {
describe('can assign', () => {
const wider: SetupContext<{ a: () => true; b: () => true }> = {} as any

expectAssignable<SetupContext<{ b: () => true }>>(wider)
})
})