UNPKG

@dvcol/svelte-utils

Version:

Svelte library for common utility functions and constants

28 lines (27 loc) 3.27 kB
import type { Component, Snippet } from 'svelte'; export type AnyComponent<Props extends Record<string, any> = any, Exports extends Record<string, any> = any, Bindings extends keyof Props | string = string> = Component<Props, Exports, Bindings>; export type LazyComponentImport<Props extends Record<string, any> = any, Exports extends Record<string, any> = any, Bindings extends keyof Props | string = string> = (() => Promise<{ default: AnyComponent<Props, Exports, Bindings>; }>) & { _isLazyComponent?: boolean; }; export type ComponentOrLazy<Props extends Record<string, any> = any, Exports extends Record<string, any> = any, Bindings extends keyof Props | string = string> = (AnyComponent<Props, Exports, Bindings> | LazyComponentImport<Props, Exports, Bindings>) & { _isLazyComponent?: boolean; }; export declare const isLazyComponent: <Props extends Record<string, any> = any, Exports extends Record<string, any> = any, Bindings extends keyof Props | string = string>(component?: ComponentOrLazy<Props, Exports, Bindings>) => component is LazyComponentImport<Props, Exports, Bindings>; export type AnySnippet = Snippet<any>; export declare const isSnippet: <Props extends Record<string, any> = any, Exports extends Record<string, any> = any, Bindings extends keyof Props | string = string>(componentOrSnippet: ComponentOrLazy<Props, Exports, Bindings> | AnySnippet) => componentOrSnippet is AnySnippet; export declare const toLazyComponent: <Props extends Record<string, any> = any, Exports extends Record<string, any> = any, Bindings extends keyof Props | string = string>(fn: () => Promise<unknown>) => LazyComponentImport<Props, Exports, Bindings>; export declare function isSyncComponentOrSnippet<Props extends Record<string, any> = any, Exports extends Record<string, any> = any, Bindings extends keyof Props | string = string>(component: ComponentOrLazy<Props, Exports, Bindings> | AnySnippet): component is AnyComponent<Props, Exports, Bindings> | AnySnippet; export declare function resolveComponent<Props extends Record<string, any> = any, Exports extends Record<string, any> = any, Bindings extends keyof Props | string = string>(component?: ComponentOrLazy<Props, Exports, Bindings> | AnySnippet, { onStart, onLoading, onLoaded, onError, }?: { onStart?: () => unknown | Promise<unknown>; onLoading?: () => unknown | Promise<unknown>; onLoaded?: (component?: Component<Props, Exports, Bindings> | AnySnippet) => unknown | Promise<unknown>; onError?: (error: unknown) => unknown | Promise<unknown>; }): Promise<Component<Props, Exports, Bindings> | AnySnippet | AnyComponent<Props, Exports, Bindings> | undefined>; export declare function resolveAsyncComponent<Props extends Record<string, any> = any, Exports extends Record<string, any> = any, Bindings extends keyof Props | string = string>(component: LazyComponentImport<Props, Exports, Bindings>, { onStart, onLoading, onLoaded, onError, }?: { onStart?: () => unknown | Promise<unknown>; onLoading?: () => unknown | Promise<unknown>; onLoaded?: (component?: Component<Props, Exports, Bindings> | AnySnippet) => unknown | Promise<unknown>; onError?: (error: unknown) => unknown | Promise<unknown>; }): Promise<AnyComponent<Props, Exports, Bindings> | undefined>;