import { default as React, Component, ReactNode, ErrorInfo, ComponentType } from 'react'; import { AppError } from './errorTypes'; /** * Error boundary hierarchy levels * - critical: App-wide errors that require full page reload * - feature: Feature/page level errors that can be isolated * - component: Component level errors with retry capability * - widget: Small UI element errors that degrade gracefully */ export type ErrorBoundaryLevel = 'critical' | 'feature' | 'component' | 'widget'; /** * Recovery action types available to error boundaries */ export type RecoveryAction = 'retry' | 'reset' | 'reload' | 'navigate' | 'escalate' | 'degrade'; /** * Error boundary context value exposed to children */ export interface ErrorBoundaryContextValue { /** Current boundary level */ level: ErrorBoundaryLevel; /** Registered boundary ID */ boundaryId: string; /** Parent boundary ID (null for root) */ parentBoundaryId: string | null; /** Report error to parent boundary */ escalateError: (error: AppError) => void; /** Reset current boundary state */ resetBoundary: () => void; /** Check if boundary is in error state */ hasError: boolean; /** Current error if any */ error: AppError | null; } /** * Props for the hierarchical error boundary component */ export interface HierarchicalErrorBoundaryProps { children: ReactNode; /** Boundary level determines behavior and styling */ level: ErrorBoundaryLevel; /** Unique boundary identifier (auto-generated if not provided) */ boundaryId?: string; /** Custom fallback component or render function */ fallback?: ReactNode | ((props: ErrorFallbackProps) => ReactNode); /** Allowed recovery actions for this boundary */ allowedActions?: RecoveryAction[]; /** Custom recovery handler */ onRecover?: (action: RecoveryAction, error: AppError) => Promise; /** Determines if error should escalate to parent */ shouldEscalate?: (error: AppError) => boolean; /** Error callback for logging/reporting */ onError?: (error: AppError, errorInfo: ErrorInfo) => void; /** Degraded component to show on error */ degradedComponent?: ReactNode; /** Maximum auto-retry attempts */ maxAutoRetry?: number; /** Auto-retry delay in ms */ autoRetryDelay?: number; } /** * Props passed to error fallback components */ export interface ErrorFallbackProps { error: AppError; level: ErrorBoundaryLevel; boundaryId: string; allowedActions: RecoveryAction[]; onAction: (action: RecoveryAction) => Promise; isRecovering: boolean; retryCount: number; } /** * Hook to access the nearest error boundary context * @throws Error if used outside of a HierarchicalErrorBoundary */ export declare function useErrorBoundary(): ErrorBoundaryContextValue; /** * Hook to access error boundary context safely (returns null if not available) */ export declare function useErrorBoundaryOptional(): ErrorBoundaryContextValue | null; /** * Hook to programmatically trigger an error in the nearest boundary */ export declare function useErrorTrigger(): (error: unknown) => void; interface HierarchicalErrorBoundaryState { hasError: boolean; error: AppError | null; isRecovering: boolean; retryCount: number; isDegraded: boolean; } /** * Hierarchical Error Boundary Component * * Provides multi-level error containment with automatic recovery strategies. * Errors are caught at the appropriate level and can either be handled locally * or escalated to parent boundaries. * * @example * ```tsx * * * * ``` */ export declare class HierarchicalErrorBoundary extends Component { static contextType: React.Context; context: ErrorBoundaryContextValue | null; private readonly boundaryId; private retryTimeoutId; constructor(props: HierarchicalErrorBoundaryProps); static getDerivedStateFromError(error: Error): Partial; componentDidCatch(error: Error, errorInfo: ErrorInfo): void; componentWillUnmount(): void; render(): ReactNode; private isRetryableError; private scheduleAutoRetry; private handleAction; private escalateError; private resetBoundary; } type PartialBoundaryProps = Omit; /** * Critical boundary - for app-wide errors * Use at the root of your application */ export declare function CriticalErrorBoundary({ children, ...props }: PartialBoundaryProps): React.JSX.Element; /** * Feature boundary - for feature/page level errors * Use around major features or route components */ export declare function FeatureErrorBoundary({ children, ...props }: PartialBoundaryProps): React.JSX.Element; /** * Component boundary - for component level errors * Use around complex components that might fail */ export declare function ComponentErrorBoundary({ children, ...props }: PartialBoundaryProps): React.JSX.Element; /** * Widget boundary - for small UI element errors * Use around widgets, cards, or small interactive elements */ export declare function WidgetErrorBoundary({ children, ...props }: PartialBoundaryProps): React.JSX.Element; /** * Higher-order component for wrapping components with error boundaries * * @example * ```tsx * const SafeComponent = withHierarchicalErrorBoundary(MyComponent, 'component'); * ``` */ export declare function withHierarchicalErrorBoundary

(WrappedComponent: ComponentType

, level: ErrorBoundaryLevel, options?: Omit): ComponentType

; export {};