UNPKG

vue-hooks-env

Version:

TypeScript and TSX Env for Vue Composition Api

60 lines (59 loc) 2.44 kB
import { Ref } from '@vue/composition-api'; import Vue, { VNode } from 'vue'; import { ClassAttributes, DomEvent, EventHandlers, HTMLAttributes, NativeEvents } from '../types'; declare module '@vue/composition-api/dist/component/component' { interface SetupContext { readonly refs: { [key: string]: Vue | Element | Vue[] | Element[]; }; } } declare global { namespace JSX { interface FunctionMode { } } } export declare type Intersection<T, K> = T & Omit<K, keyof T>; export declare type EventBase = { [K in string]?: any; }; export declare type SlotBase = { [K in string]?: any; }; interface DefaultSlot { default?: () => VNode[]; } export interface HookContext<A, E extends EventBase, S extends SlotBase> { readonly attrs: A; readonly slots: S; readonly listeners: { [key: string]: Function; }; bindRefKey<T>(ref?: Ref<T> | ((value: T) => void)): string; renderSlot<K extends keyof S>(event: K, fallback?: VNode[] | VNode | null, ...args: Parameters<NonNullable<S[K]>>): VNode[]; emit<K extends keyof E>(event: K, ...args: Parameters<NonNullable<E[K]>>): void; } export declare type HookSetupFunction<P, A, E extends EventBase, S extends SlotBase> = (this: void, props: P, ctx: HookContext<Omit<A, keyof P>, Intersection<E, DomEvent>, S>) => () => VNode | null; export declare type ComponentRender<P, A> = { $props: P; $attrs: A; } & P & Vue; export declare type ComponentResult<P, A = HTMLAttributes> = JSX.FunctionMode extends { enable: true; } ? VNode : ComponentRender<P, Omit<A, keyof P>>; export interface VueComponentOptions { props: string[]; name?: string; inheritAttrs?: boolean; } export declare type CombineProps<P, A = HTMLAttributes, E extends EventBase = {}, S extends SlotBase = DefaultSlot> = P & ClassAttributes<Omit<A, keyof P>, Intersection<E, DomEvent>, S> & Omit<A, keyof P> & Intersection<E, DomEvent> & EventHandlers<NativeEvents>; export interface VC<P, A = HTMLAttributes, E extends EventBase = {}, S extends SlotBase = { default?: () => VNode[]; }> extends VueComponentOptions { (props: CombineProps<P, A, E, S>): ComponentResult<P, A>; } export declare function HC<P, A = HTMLAttributes, E extends EventBase = {}, S extends SlotBase = { default?: () => VNode[]; }>(setup: HookSetupFunction<P, A, E, S>, props?: Array<keyof P>, name?: string): VC<P, A, E, S>; export {};