fix(types): allow assigning wider SetupContext type (#2818)

fix #2362
This commit is contained in:
翠 / green 2022-11-14 18:33:29 +09:00 committed by GitHub
parent 588bd44f03
commit eb2a83283c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -180,12 +180,15 @@ export const enum LifecycleHooks {
SERVER_PREFETCH = 'sp' SERVER_PREFETCH = 'sp'
} }
export interface SetupContext<E = EmitsOptions> { // use `E extends any` to force evaluating type to fix #2362
attrs: Data export type SetupContext<E = EmitsOptions> = E extends any
slots: Slots ? {
emit: EmitFn<E> attrs: Data
expose: (exposed?: Record<string, any>) => void slots: Slots
} emit: EmitFn<E>
expose: (exposed?: Record<string, any>) => void
}
: never
/** /**
* @internal * @internal

View File

@ -11,7 +11,9 @@ import {
FunctionalComponent, FunctionalComponent,
ComponentPublicInstance, ComponentPublicInstance,
toRefs, toRefs,
IsAny IsAny,
SetupContext,
expectAssignable
} from './index' } from './index'
declare function extractComponentOptions<Props, RawBindings>( declare function extractComponentOptions<Props, RawBindings>(
@ -476,3 +478,11 @@ describe('class', () => {
expectType<number>(props.foo) expectType<number>(props.foo)
}) })
describe('SetupContext', () => {
describe('can assign', () => {
const wider: SetupContext<{ a: () => true; b: () => true }> = {} as any
expectAssignable<SetupContext<{ b: () => true }>>(wider)
})
})