export = preact; export as namespace preact; import { JSXInternal } from './jsx'; declare namespace preact { export import JSX = JSXInternal; // // Preact Virtual DOM // ----------------------------------- interface VNode

{ type: ComponentType

| string; props: P & { children: ComponentChildren }; key: Key; /** * ref is not guaranteed by React.ReactElement, for compatiblity reasons * with popular react libs we define it as optional too */ ref?: Ref | null; /** * The time this `vnode` started rendering. Will only be set when * the devtools are attached. * Default value: `0` */ startTime?: number; /** * The time that the rendering of this `vnode` was completed. Will only be * set when the devtools are attached. * Default value: `-1` */ endTime?: number; } // // Preact Component interface // ----------------------------------- type Key = string | number | any; type RefObject = { current?: T | null }; type RefCallback = (instance: T | null) => void; type Ref = RefObject | RefCallback; type ComponentChild = | VNode | object | string | number | boolean | null | undefined; type ComponentChildren = ComponentChild[] | ComponentChild; interface Attributes { key?: Key; jsx?: boolean; } interface ClassAttributes extends Attributes { ref?: Ref; } interface PreactDOMAttributes { children?: ComponentChildren; dangerouslySetInnerHTML?: { __html: string; }; } type RenderableProps = P & Readonly }>; type ComponentType

= ComponentClass

| FunctionComponent

; type ComponentFactory

= ComponentType

; type ComponentProps> = C extends ComponentType< infer P > ? P : never; interface FunctionComponent

{ (props: RenderableProps

, context?: any): VNode | null; displayName?: string; defaultProps?: Partial

; } interface FunctionalComponent

extends FunctionComponent

{} interface ComponentClass

{ new (props: P, context?: any): Component; displayName?: string; defaultProps?: Partial

; getDerivedStateFromProps?( props: Readonly

, state: Readonly ): Partial | null; getDerivedStateFromError?(error: any): Partial | null; } interface ComponentConstructor

extends ComponentClass {} // Type alias for a component instance considered generally, whether stateless or stateful. type AnyComponent

= FunctionComponent

| Component; interface Component

{ componentWillMount?(): void; componentDidMount?(): void; componentWillUnmount?(): void; getChildContext?(): object; componentWillReceiveProps?(nextProps: Readonly

, nextContext: any): void; shouldComponentUpdate?( nextProps: Readonly

, nextState: Readonly, nextContext: any ): boolean; componentWillUpdate?( nextProps: Readonly

, nextState: Readonly, nextContext: any ): void; getSnapshotBeforeUpdate?(oldProps: Readonly

, oldState: Readonly): any; componentDidUpdate?( previousProps: Readonly

, previousState: Readonly, snapshot: any ): void; componentDidCatch?(error: any, errorInfo: any): void; } abstract class Component { constructor(props?: P, context?: any); static displayName?: string; static defaultProps?: any; static contextType?: Context; // Static members cannot reference class type parameters. This is not // supported in TypeScript. Reusing the same type arguments from `Component` // will lead to an impossible state where one cannot satisfy the type // constraint under no circumstances, see #1356.In general type arguments // seem to be a bit buggy and not supported well at the time of this // writing with TS 3.3.3333. static getDerivedStateFromProps?( props: Readonly, state: Readonly ): object | null; static getDerivedStateFromError?(error: any): object | null; state: Readonly; props: RenderableProps

; context: any; base?: Element | Text; // From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e836acc75a78cf0655b5dfdbe81d69fdd4d8a252/types/react/index.d.ts#L402 // // We MUST keep setState() as a unified signature because it allows proper checking of the method return type. // // See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257 setState( state: | (( prevState: Readonly, props: Readonly

) => Pick | Partial | null) | (Pick | Partial | null), callback?: () => void ): void; forceUpdate(callback?: () => void): void; abstract render( props?: RenderableProps

, state?: Readonly, context?: any ): ComponentChild; } // // Preact createElement // ----------------------------------- function createElement( type: string, props: | (JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record) | null, ...children: ComponentChildren[] ): VNode; function createElement

( type: ComponentType

, props: (Attributes & P) | null, ...children: ComponentChildren[] ): VNode; namespace createElement { export import JSX = JSXInternal; } function h( type: string, props: | (JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record) | null, ...children: ComponentChildren[] ): VNode; function h

( type: ComponentType

, props: (Attributes & P) | null, ...children: ComponentChildren[] ): VNode; namespace h { export import JSX = JSXInternal; } // // Preact render // ----------------------------------- function render( vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment, replaceNode?: Element | Text ): void; function hydrate( vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment ): void; function cloneElement( vnode: VNode, props?: any, ...children: ComponentChildren[] ): VNode; function cloneElement

( vnode: VNode

, props?: any, ...children: ComponentChildren[] ): VNode

; // // Preact Built-in Components // ----------------------------------- // TODO: Revisit what the public type of this is... const Fragment: ComponentClass<{}, {}>; // // Preact options // ----------------------------------- /** * Global options for preact */ interface Options { /** Attach a hook that is invoked whenever a VNode is created. */ vnode?(vnode: VNode): void; /** Attach a hook that is invoked immediately before a vnode is unmounted. */ unmount?(vnode: VNode): void; /** Attach a hook that is invoked after a vnode has rendered. */ diffed?(vnode: VNode): void; event?(e: Event): any; requestAnimationFrame?: typeof requestAnimationFrame; debounceRendering?(cb: () => void): void; useDebugValue?(value: string | number): void; __suspenseDidResolve?(vnode: VNode, cb: () => void): void; // __canSuspenseResolve?(vnode: VNode, cb: () => void): void; } const options: Options; // // Preact helpers // ----------------------------------- function createRef(): RefObject; function toChildArray( children: ComponentChildren ): Array; function isValidElement(vnode: any): vnode is VNode; // // Context // ----------------------------------- interface Consumer extends FunctionComponent<{ children: (value: T) => ComponentChildren; }> {} interface PreactConsumer extends Consumer {} interface Provider extends FunctionComponent<{ value: T; children: ComponentChildren; }> {} interface PreactProvider extends Provider {} interface Context { Consumer: Consumer; Provider: Provider; } interface PreactContext extends Context {} function createContext(defaultValue: T): Context; }