;
getDerivedStateFromProps?(
props: Readonly,
state: Readonly
): Partial | null;
getDerivedStateFromError?(error: any): Partial | null;
}
export interface ComponentConstructor
extends ComponentClass
{}
export type AnyComponent
=
| FunctionComponent
| Component
;
export 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;
}
export 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;
}
export function createElement(
type: string,
props:
| (JSXInternal.HTMLAttributes &
JSXInternal.SVGAttributes &
Record)
| null,
...children: ComponentChildren[]
): VNode;
export function createElement(
type: ComponentType
,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode;
export namespace createElement {
export import JSX = JSXInternal;
}
export function h(
type: string,
props:
| (JSXInternal.HTMLAttributes &
JSXInternal.SVGAttributes &
Record)
| null,
...children: ComponentChildren[]
): VNode;
export function h(
type: ComponentType
,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode;
export namespace h {
export import JSX = JSXInternal;
}
export function render(
vnode: ComponentChild,
parent: Element | Document | ShadowRoot | DocumentFragment,
replaceNode?: Element | Text
): void;
export function hydrate(
vnode: ComponentChild,
parent: Element | Document | ShadowRoot | DocumentFragment
): void;
export function cloneElement(
vnode: VNode,
props?: any,
...children: ComponentChildren[]
): VNode;
export function cloneElement(
vnode: VNode
,
props?: any,
...children: ComponentChildren[]
): VNode
;
export const Fragment: ComponentClass<{}, {}>;
/**
* Global options for preact
*/
export 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;
_addHookName?(name: string | number): void;
__suspenseDidResolve?(vnode: VNode, cb: () => void): void;
// __canSuspenseResolve?(vnode: VNode, cb: () => void): void;
}
export const options: Options;
export function createRef(): RefObject;
export function toChildArray(
children: ComponentChildren
): Array;
export function isValidElement(vnode: any): vnode is VNode;
export interface Consumer
extends FunctionComponent<{
children: (value: T) => ComponentChildren;
}> {}
export interface PreactConsumer extends Consumer {}
export interface Provider
extends FunctionComponent<{
value: T;
children: ComponentChildren;
}> {}
export interface PreactProvider extends Provider {}
export interface Context {
Consumer: Consumer;
Provider: Provider;
displayName?: string;
}
export interface PreactContext extends Context {}
export function createContext(defaultValue: T): Context;
}
declare module 'preact/jsx' {
import {
ClassAttributes,
Component,
PreactDOMAttributes,
VNode
} from './';
type Defaultize =
// Distribute over unions
Props extends any // Make any properties included in Default optional
? Partial>> & // Include the remaining properties from Props
Pick>
: never;
export namespace JSXInternal {
export type LibraryManagedAttributes = Component extends {
defaultProps: infer Defaults;
}
? Defaultize
: Props;
export interface IntrinsicAttributes {
key?: any;
}
export interface Element extends VNode {}
export interface ElementClass extends Component {}
export interface ElementAttributesProperty {
props: any;
}
export interface ElementChildrenAttribute {
children: any;
}
export type DOMCSSProperties = {
[key in keyof Omit<
CSSStyleDeclaration,
| 'item'
| 'setProperty'
| 'removeProperty'
| 'getPropertyValue'
| 'getPropertyPriority'
>]?: string | number | null | undefined;
};
export type AllCSSProperties = {
[key: string]: string | number | null | undefined;
};
export interface CSSProperties extends AllCSSProperties, DOMCSSProperties {
cssText?: string | null;
}
export interface SVGAttributes
extends HTMLAttributes {
accentHeight?: number | string;
accumulate?: 'none' | 'sum';
additive?: 'replace' | 'sum';
alignmentBaseline?:
| 'auto'
| 'baseline'
| 'before-edge'
| 'text-before-edge'
| 'middle'
| 'central'
| 'after-edge'
| 'text-after-edge'
| 'ideographic'
| 'alphabetic'
| 'hanging'
| 'mathematical'
| 'inherit';
allowReorder?: 'no' | 'yes';
alphabetic?: number | string;
amplitude?: number | string;
arabicForm?: 'initial' | 'medial' | 'terminal' | 'isolated';
ascent?: number | string;
attributeName?: string;
attributeType?: string;
autoReverse?: number | string;
azimuth?: number | string;
baseFrequency?: number | string;
baselineShift?: number | string;
baseProfile?: number | string;
bbox?: number | string;
begin?: number | string;
bias?: number | string;
by?: number | string;
calcMode?: number | string;
capHeight?: number | string;
clip?: number | string;
clipPath?: string;
clipPathUnits?: number | string;
clipRule?: number | string;
colorInterpolation?: number | string;
colorInterpolationFilters?: 'auto' | 'sRGB' | 'linearRGB' | 'inherit';
colorProfile?: number | string;
colorRendering?: number | string;
contentScriptType?: number | string;
contentStyleType?: number | string;
cursor?: number | string;
cx?: number | string;
cy?: number | string;
d?: string;
decelerate?: number | string;
descent?: number | string;
diffuseConstant?: number | string;
direction?: number | string;
display?: number | string;
divisor?: number | string;
dominantBaseline?: number | string;
dur?: number | string;
dx?: number | string;
dy?: number | string;
edgeMode?: number | string;
elevation?: number | string;
enableBackground?: number | string;
end?: number | string;
exponent?: number | string;
externalResourcesRequired?: number | string;
fill?: string;
fillOpacity?: number | string;
fillRule?: 'nonzero' | 'evenodd' | 'inherit';
filter?: string;
filterRes?: number | string;
filterUnits?: number | string;
floodColor?: number | string;
floodOpacity?: number | string;
focusable?: number | string;
fontFamily?: string;
fontSize?: number | string;
fontSizeAdjust?: number | string;
fontStretch?: number | string;
fontStyle?: number | string;
fontVariant?: number | string;
fontWeight?: number | string;
format?: number | string;
from?: number | string;
fx?: number | string;
fy?: number | string;
g1?: number | string;
g2?: number | string;
glyphName?: number | string;
glyphOrientationHorizontal?: number | string;
glyphOrientationVertical?: number | string;
glyphRef?: number | string;
gradientTransform?: string;
gradientUnits?: string;
hanging?: number | string;
horizAdvX?: number | string;
horizOriginX?: number | string;
ideographic?: number | string;
imageRendering?: number | string;
in2?: number | string;
in?: string;
intercept?: number | string;
k1?: number | string;
k2?: number | string;
k3?: number | string;
k4?: number | string;
k?: number | string;
kernelMatrix?: number | string;
kernelUnitLength?: number | string;
kerning?: number | string;
keyPoints?: number | string;
keySplines?: number | string;
keyTimes?: number | string;
lengthAdjust?: number | string;
letterSpacing?: number | string;
lightingColor?: number | string;
limitingConeAngle?: number | string;
local?: number | string;
markerEnd?: string;
markerHeight?: number | string;
markerMid?: string;
markerStart?: string;
markerUnits?: number | string;
markerWidth?: number | string;
mask?: string;
maskContentUnits?: number | string;
maskUnits?: number | string;
mathematical?: number | string;
mode?: number | string;
numOctaves?: number | string;
offset?: number | string;
opacity?: number | string;
operator?: number | string;
order?: number | string;
orient?: number | string;
orientation?: number | string;
origin?: number | string;
overflow?: number | string;
overlinePosition?: number | string;
overlineThickness?: number | string;
paintOrder?: number | string;
panose1?: number | string;
pathLength?: number | string;
patternContentUnits?: string;
patternTransform?: number | string;
patternUnits?: string;
pointerEvents?: number | string;
points?: string;
pointsAtX?: number | string;
pointsAtY?: number | string;
pointsAtZ?: number | string;
preserveAlpha?: number | string;
preserveAspectRatio?: string;
primitiveUnits?: number | string;
r?: number | string;
radius?: number | string;
refX?: number | string;
refY?: number | string;
renderingIntent?: number | string;
repeatCount?: number | string;
repeatDur?: number | string;
requiredExtensions?: number | string;
requiredFeatures?: number | string;
restart?: number | string;
result?: string;
rotate?: number | string;
rx?: number | string;
ry?: number | string;
scale?: number | string;
seed?: number | string;
shapeRendering?: number | string;
slope?: number | string;
spacing?: number | string;
specularConstant?: number | string;
specularExponent?: number | string;
speed?: number | string;
spreadMethod?: string;
startOffset?: number | string;
stdDeviation?: number | string;
stemh?: number | string;
stemv?: number | string;
stitchTiles?: number | string;
stopColor?: string;
stopOpacity?: number | string;
strikethroughPosition?: number | string;
strikethroughThickness?: number | string;
string?: number | string;
stroke?: string;
strokeDasharray?: string | number;
strokeDashoffset?: string | number;
strokeLinecap?: 'butt' | 'round' | 'square' | 'inherit';
strokeLinejoin?: 'miter' | 'round' | 'bevel' | 'inherit';
strokeMiterlimit?: string | number;
strokeOpacity?: number | string;
strokeWidth?: number | string;
surfaceScale?: number | string;
systemLanguage?: number | string;
tableValues?: number | string;
targetX?: number | string;
targetY?: number | string;
textAnchor?: string;
textDecoration?: number | string;
textLength?: number | string;
textRendering?: number | string;
to?: number | string;
transform?: string;
u1?: number | string;
u2?: number | string;
underlinePosition?: number | string;
underlineThickness?: number | string;
unicode?: number | string;
unicodeBidi?: number | string;
unicodeRange?: number | string;
unitsPerEm?: number | string;
vAlphabetic?: number | string;
values?: string;
vectorEffect?: number | string;
version?: string;
vertAdvY?: number | string;
vertOriginX?: number | string;
vertOriginY?: number | string;
vHanging?: number | string;
vIdeographic?: number | string;
viewBox?: string;
viewTarget?: number | string;
visibility?: number | string;
vMathematical?: number | string;
widths?: number | string;
wordSpacing?: number | string;
writingMode?: number | string;
x1?: number | string;
x2?: number | string;
x?: number | string;
xChannelSelector?: string;
xHeight?: number | string;
xlinkActuate?: string;
xlinkArcrole?: string;
xlinkHref?: string;
xlinkRole?: string;
xlinkShow?: string;
xlinkTitle?: string;
xlinkType?: string;
xmlBase?: string;
xmlLang?: string;
xmlns?: string;
xmlnsXlink?: string;
xmlSpace?: string;
y1?: number | string;
y2?: number | string;
y?: number | string;
yChannelSelector?: string;
z?: number | string;
zoomAndPan?: string;
}
export interface PathAttributes {
d: string;
}
export type TargetedEvent<
Target extends EventTarget = EventTarget,
TypedEvent extends Event = Event
> = Omit & {
readonly currentTarget: Target;
};
export type TargetedAnimationEvent<
Target extends EventTarget
> = TargetedEvent;
export type TargetedClipboardEvent<
Target extends EventTarget
> = TargetedEvent;
export type TargetedCompositionEvent<
Target extends EventTarget
> = TargetedEvent;
export type TargetedDragEvent = TargetedEvent<
Target,
DragEvent
>;
export type TargetedFocusEvent = TargetedEvent<
Target,
FocusEvent
>;
export type TargetedKeyboardEvent = TargetedEvent<
Target,
KeyboardEvent
>;
export type TargetedMouseEvent = TargetedEvent<
Target,
MouseEvent
>;
export type TargetedPointerEvent = TargetedEvent<
Target,
PointerEvent
>;
export type TargetedTouchEvent = TargetedEvent<
Target,
TouchEvent
>;
export type TargetedTransitionEvent<
Target extends EventTarget
> = TargetedEvent;
export type TargetedUIEvent = TargetedEvent<
Target,
UIEvent
>;
export type TargetedWheelEvent = TargetedEvent<
Target,
WheelEvent
>;
export interface EventHandler {
/**
* The `this` keyword always points to the DOM element the event handler
* was invoked on. See: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Event_handlers#Event_handlers_parameters_this_binding_and_the_return_value
*/
(this: never, event: E): void;
}
export type AnimationEventHandler = EventHandler<
TargetedAnimationEvent
>;
export type ClipboardEventHandler = EventHandler<
TargetedClipboardEvent
>;
export type CompositionEventHandler<
Target extends EventTarget
> = EventHandler>;
export type DragEventHandler = EventHandler<
TargetedDragEvent
>;
export type FocusEventHandler = EventHandler<
TargetedFocusEvent
>;
export type GenericEventHandler = EventHandler<
TargetedEvent
>;
export type KeyboardEventHandler = EventHandler<
TargetedKeyboardEvent
>;
export type MouseEventHandler = EventHandler<
TargetedMouseEvent
>;
export type PointerEventHandler = EventHandler<
TargetedPointerEvent
>;
export type TouchEventHandler = EventHandler<
TargetedTouchEvent
>;
export type TransitionEventHandler = EventHandler<
TargetedTransitionEvent
>;
export type UIEventHandler = EventHandler<
TargetedUIEvent
>;
export type WheelEventHandler = EventHandler<
TargetedWheelEvent
>;
export interface DOMAttributes
extends PreactDOMAttributes {
// Image Events
onLoad?: GenericEventHandler;
onLoadCapture?: GenericEventHandler;
onError?: GenericEventHandler;
onErrorCapture?: GenericEventHandler;
// Clipboard Events
onCopy?: ClipboardEventHandler;
onCopyCapture?: ClipboardEventHandler;
onCut?: ClipboardEventHandler;
onCutCapture?: ClipboardEventHandler;
onPaste?: ClipboardEventHandler;
onPasteCapture?: ClipboardEventHandler;
// Composition Events
onCompositionEnd?: CompositionEventHandler;
onCompositionEndCapture?: CompositionEventHandler;
onCompositionStart?: CompositionEventHandler;
onCompositionStartCapture?: CompositionEventHandler;
onCompositionUpdate?: CompositionEventHandler;
onCompositionUpdateCapture?: CompositionEventHandler;
// Details Events
onToggle?: GenericEventHandler;
// Focus Events
onFocus?: FocusEventHandler;
onFocusCapture?: FocusEventHandler;
onfocusin?: FocusEventHandler;
onfocusinCapture?: FocusEventHandler;
onfocusout?: FocusEventHandler;
onfocusoutCapture?: FocusEventHandler;
onBlur?: FocusEventHandler;
onBlurCapture?: FocusEventHandler;
// Form Events
onChange?: GenericEventHandler;
onChangeCapture?: GenericEventHandler;
onInput?: GenericEventHandler;
onInputCapture?: GenericEventHandler;
onBeforeInput?: GenericEventHandler;
onBeforeInputCapture?: GenericEventHandler;
onSearch?: GenericEventHandler;
onSearchCapture?: GenericEventHandler;
onSubmit?: GenericEventHandler;
onSubmitCapture?: GenericEventHandler;
onInvalid?: GenericEventHandler;
onInvalidCapture?: GenericEventHandler;
onReset?: GenericEventHandler;
onResetCapture?: GenericEventHandler;
onFormData?: GenericEventHandler;
onFormDataCapture?: GenericEventHandler;
// Keyboard Events
onKeyDown?: KeyboardEventHandler;
onKeyDownCapture?: KeyboardEventHandler;
onKeyPress?: KeyboardEventHandler;
onKeyPressCapture?: KeyboardEventHandler;
onKeyUp?: KeyboardEventHandler;
onKeyUpCapture?: KeyboardEventHandler;
// Media Events
onAbort?: GenericEventHandler;
onAbortCapture?: GenericEventHandler;
onCanPlay?: GenericEventHandler;
onCanPlayCapture?: GenericEventHandler;
onCanPlayThrough?: GenericEventHandler;
onCanPlayThroughCapture?: GenericEventHandler;
onDurationChange?: GenericEventHandler;
onDurationChangeCapture?: GenericEventHandler;
onEmptied?: GenericEventHandler;
onEmptiedCapture?: GenericEventHandler;
onEncrypted?: GenericEventHandler;
onEncryptedCapture?: GenericEventHandler;
onEnded?: GenericEventHandler;
onEndedCapture?: GenericEventHandler;
onLoadedData?: GenericEventHandler;
onLoadedDataCapture?: GenericEventHandler;
onLoadedMetadata?: GenericEventHandler;
onLoadedMetadataCapture?: GenericEventHandler;
onLoadStart?: GenericEventHandler;
onLoadStartCapture?: GenericEventHandler;
onPause?: GenericEventHandler;
onPauseCapture?: GenericEventHandler;
onPlay?: GenericEventHandler;
onPlayCapture?: GenericEventHandler;
onPlaying?: GenericEventHandler;
onPlayingCapture?: GenericEventHandler;
onProgress?: GenericEventHandler;
onProgressCapture?: GenericEventHandler;
onRateChange?: GenericEventHandler;
onRateChangeCapture?: GenericEventHandler;
onSeeked?: GenericEventHandler;
onSeekedCapture?: GenericEventHandler;
onSeeking?: GenericEventHandler;
onSeekingCapture?: GenericEventHandler;
onStalled?: GenericEventHandler;
onStalledCapture?: GenericEventHandler;
onSuspend?: GenericEventHandler;
onSuspendCapture?: GenericEventHandler;
onTimeUpdate?: GenericEventHandler;
onTimeUpdateCapture?: GenericEventHandler;
onVolumeChange?: GenericEventHandler;
onVolumeChangeCapture?: GenericEventHandler;
onWaiting?: GenericEventHandler;
onWaitingCapture?: GenericEventHandler;
// MouseEvents
onClick?: MouseEventHandler;
onClickCapture?: MouseEventHandler;
onContextMenu?: MouseEventHandler;
onContextMenuCapture?: MouseEventHandler;
onDblClick?: MouseEventHandler;
onDblClickCapture?: MouseEventHandler;
onDrag?: DragEventHandler;
onDragCapture?: DragEventHandler;
onDragEnd?: DragEventHandler;
onDragEndCapture?: DragEventHandler;
onDragEnter?: DragEventHandler;
onDragEnterCapture?: DragEventHandler;
onDragExit?: DragEventHandler;
onDragExitCapture?: DragEventHandler;
onDragLeave?: DragEventHandler;
onDragLeaveCapture?: DragEventHandler;
onDragOver?: DragEventHandler;
onDragOverCapture?: DragEventHandler;
onDragStart?: DragEventHandler;
onDragStartCapture?: DragEventHandler;
onDrop?: DragEventHandler;
onDropCapture?: DragEventHandler;
onMouseDown?: MouseEventHandler;
onMouseDownCapture?: MouseEventHandler;
onMouseEnter?: MouseEventHandler;
onMouseEnterCapture?: MouseEventHandler;
onMouseLeave?: MouseEventHandler;
onMouseLeaveCapture?: MouseEventHandler;
onMouseMove?: MouseEventHandler;
onMouseMoveCapture?: MouseEventHandler;
onMouseOut?: MouseEventHandler;
onMouseOutCapture?: MouseEventHandler;
onMouseOver?: MouseEventHandler;
onMouseOverCapture?: MouseEventHandler;
onMouseUp?: MouseEventHandler;
onMouseUpCapture?: MouseEventHandler;
// Selection Events
onSelect?: GenericEventHandler;
onSelectCapture?: GenericEventHandler;
// Touch Events
onTouchCancel?: TouchEventHandler;
onTouchCancelCapture?: TouchEventHandler;
onTouchEnd?: TouchEventHandler;
onTouchEndCapture?: TouchEventHandler;
onTouchMove?: TouchEventHandler;
onTouchMoveCapture?: TouchEventHandler;
onTouchStart?: TouchEventHandler;
onTouchStartCapture?: TouchEventHandler;
// Pointer Events
onPointerOver?: PointerEventHandler;
onPointerOverCapture?: PointerEventHandler;
onPointerEnter?: PointerEventHandler;
onPointerEnterCapture?: PointerEventHandler;
onPointerDown?: PointerEventHandler;
onPointerDownCapture?: PointerEventHandler;
onPointerMove?: PointerEventHandler;
onPointerMoveCapture?: PointerEventHandler;
onPointerUp?: PointerEventHandler;
onPointerUpCapture?: PointerEventHandler;
onPointerCancel?: PointerEventHandler;
onPointerCancelCapture?: PointerEventHandler;
onPointerOut?: PointerEventHandler;
onPointerOutCapture?: PointerEventHandler;
onPointerLeave?: PointerEventHandler;
onPointerLeaveCapture?: PointerEventHandler