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: resolve conflicts with vue2 interface #869

Merged
merged 4 commits into from Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/component/componentProxy.ts
Expand Up @@ -19,6 +19,7 @@ import {
} from './componentOptions'
import {
ComponentInternalInstance,
ComponentRenderEmitFn,
EmitFn,
EmitsOptions,
ObjectEmitsOptions,
Expand Down Expand Up @@ -67,8 +68,8 @@ export type ComponentRenderProxy<
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
: P & PublicProps
>
$attrs: Data
$emit: EmitFn<Emits>
$attrs: Record<string, string>
$emit: ComponentRenderEmitFn<Emits>
} & Readonly<P> &
ShallowUnwrapRef<B> &
D &
Expand Down
18 changes: 13 additions & 5 deletions src/runtimeContext.ts
@@ -1,4 +1,5 @@
import type { VueConstructor, VNode } from 'vue'
import Vue$1 from 'vue'
import { bindCurrentScopeToVM, EffectScope } from './apis/effectScope'
import { ComponentInstance, Data } from './component'
import {
Expand Down Expand Up @@ -121,19 +122,26 @@ export type EmitsOptions = ObjectEmitsOptions | string[]

export type EmitFn<
Options = ObjectEmitsOptions,
Event extends keyof Options = keyof Options
Event extends keyof Options = keyof Options,
ReturnType extends void | Vue$1 = void
> = Options extends Array<infer V>
? (event: V, ...args: any[]) => void
? (event: V, ...args: any[]) => ReturnType
: {} extends Options // if the emit is empty object (usually the default value for emit) should be converted to function
? (event: string, ...args: any[]) => void
? (event: string, ...args: any[]) => ReturnType
: UnionToIntersection<
{
[key in Event]: Options[key] extends (...args: infer Args) => any
? (event: key, ...args: Args) => void
: (event: key, ...args: any[]) => void
? (event: key, ...args: Args) => ReturnType
: (event: key, ...args: any[]) => ReturnType
}[Event]
>

export type ComponentRenderEmitFn<
Options = ObjectEmitsOptions,
Event extends keyof Options = keyof Options,
V extends Vue$1 = Vue$1
> = EmitFn<Options, Event, V>

export type Slots = Readonly<InternalSlots>

export interface SetupContext<E = EmitsOptions> {
Expand Down