// Type definitions for React v0.14 // Project: http://facebook.github.io/react/ // Definitions by: Asana , AssureSign , Microsoft // Definitions: https://github.com/borisyankov/DefinitelyTyped declare namespace __React { // // React Elements // ---------------------------------------------------------------------- type ReactType = string | ComponentClass | StatelessComponent; type Key = string | number; type Ref = string | ((instance: T) => any); interface Attributes { key?: Key; } interface ClassAttributes extends Attributes { ref?: Ref; } interface ReactElement

> { type: string | ComponentClass

| StatelessComponent

; props: P; key?: Key; } interface ClassicElement

extends ReactElement

{ type: ClassicComponentClass

; ref: Ref>; } interface DOMElement

extends ReactElement

{ type: string; ref: Ref; } interface ReactHTMLElement extends DOMElement { ref: Ref; } interface ReactSVGElement extends DOMElement { ref: Ref; } // // Factories // ---------------------------------------------------------------------- interface Factory

{ (props?: P & Attributes, ...children: ReactNode[]): ReactElement

; } interface ClassicFactory

extends Factory

{ (props?: P & ClassAttributes>, ...children: ReactNode[]): ClassicElement

; } interface DOMFactory

{ (props?: P & ClassAttributes, ...children: ReactNode[]): DOMElement

; } type HTMLFactory = DOMFactory; type SVGFactory = DOMFactory; // // React Nodes // http://facebook.github.io/react/docs/glossary.html // ---------------------------------------------------------------------- type ReactText = string | number; type ReactChild = ReactElement | ReactText; // Should be Array but type aliases cannot be recursive type ReactFragment = {} | Array; type ReactNode = ReactChild | ReactFragment | boolean; // // Top Level API // ---------------------------------------------------------------------- function createClass(spec: ComponentSpec): ClassicComponentClass

; function createFactory

(type: string): DOMFactory

; function createFactory

(type: ClassicComponentClass

): ClassicFactory

; function createFactory

(type: ComponentClass

| StatelessComponent

): Factory

; function createElement

( type: string, props?: P & ClassAttributes, ...children: ReactNode[]): DOMElement

; function createElement

( type: ClassicComponentClass

, props?: P & ClassAttributes>, ...children: ReactNode[]): ClassicElement

; function createElement

( type: ComponentClass

| StatelessComponent

, props?: P & ClassAttributes>, ...children: ReactNode[]): ReactElement

; function cloneElement( element: ReactHTMLElement, props?: HTMLAttributes & ClassAttributes, ...children: ReactNode[]): ReactHTMLElement; function cloneElement( element: ReactSVGElement, props?: SVGAttributes & ClassAttributes, ...children: ReactNode[]): ReactSVGElement; function cloneElement

( element: ClassicElement

, props?: Q & ClassAttributes>, ...children: ReactNode[]): ClassicElement

; function cloneElement

( element: ReactElement

, props?: Q & Attributes, ...children: ReactNode[]): ReactElement

; function isValidElement

(object: {}): object is ReactElement

; var DOM: ReactDOM; var PropTypes: ReactPropTypes; var Children: ReactChildren; // // Component API // ---------------------------------------------------------------------- type ReactInstance = Component | Element; // Base component for plain JS classes class Component implements ComponentLifecycle { constructor(props?: P, context?: any); setState(f: (prevState: S, props: P) => S, callback?: () => any): void; setState(state: S, callback?: () => any): void; forceUpdate(callBack?: () => any): void; render(): JSX.Element; // React.Props is now deprecated, which means that the `children` // property is not available on `P` by default, even though you can // always pass children as variadic arguments to `createElement`. // In the future, if we can define its call signature conditionallly // on the existence of `children` in `P`, then we should remove this. props: P & { children?: ReactNode }; state: S; context: {}; refs: { [key: string]: ReactInstance }; } interface ClassicComponent extends Component { replaceState(nextState: S, callback?: () => any): void; isMounted(): boolean; getInitialState?(): S; } interface ChildContextProvider { getChildContext(): CC; } // // Class Interfaces // ---------------------------------------------------------------------- interface StatelessComponent

{ (props?: P, context?: any): ReactElement; propTypes?: ValidationMap

; contextTypes?: ValidationMap; defaultProps?: P; displayName?: string; } interface ComponentClass

{ new(props?: P, context?: any): Component; propTypes?: ValidationMap

; contextTypes?: ValidationMap; childContextTypes?: ValidationMap; defaultProps?: P; } interface ClassicComponentClass

extends ComponentClass

{ new(props?: P, context?: any): ClassicComponent; getDefaultProps?(): P; displayName?: string; } // // Component Specs and Lifecycle // ---------------------------------------------------------------------- interface ComponentLifecycle { componentWillMount?(): void; componentDidMount?(): void; componentWillReceiveProps?(nextProps: P, nextContext: any): void; shouldComponentUpdate?(nextProps: P, nextState: S, nextContext: any): boolean; componentWillUpdate?(nextProps: P, nextState: S, nextContext: any): void; componentDidUpdate?(prevProps: P, prevState: S, prevContext: any): void; componentWillUnmount?(): void; } interface Mixin extends ComponentLifecycle { mixins?: Mixin; statics?: { [key: string]: any; }; displayName?: string; propTypes?: ValidationMap; contextTypes?: ValidationMap; childContextTypes?: ValidationMap; getDefaultProps?(): P; getInitialState?(): S; } interface ComponentSpec extends Mixin { render(): ReactElement; [propertyName: string]: any; } // // Event System // ---------------------------------------------------------------------- interface SyntheticEvent { bubbles: boolean; cancelable: boolean; currentTarget: EventTarget; defaultPrevented: boolean; eventPhase: number; isTrusted: boolean; nativeEvent: Event; preventDefault(): void; stopPropagation(): void; target: EventTarget; timeStamp: Date; type: string; } interface ClipboardEvent extends SyntheticEvent { clipboardData: DataTransfer; } interface CompositionEvent extends SyntheticEvent { data: string; } interface DragEvent extends SyntheticEvent { dataTransfer: DataTransfer; } interface FocusEvent extends SyntheticEvent { relatedTarget: EventTarget; } interface FormEvent extends SyntheticEvent { } interface KeyboardEvent extends SyntheticEvent { altKey: boolean; charCode: number; ctrlKey: boolean; getModifierState(key: string): boolean; key: string; keyCode: number; locale: string; location: number; metaKey: boolean; repeat: boolean; shiftKey: boolean; which: number; } interface MouseEvent extends SyntheticEvent { altKey: boolean; button: number; buttons: number; clientX: number; clientY: number; ctrlKey: boolean; getModifierState(key: string): boolean; metaKey: boolean; pageX: number; pageY: number; relatedTarget: EventTarget; screenX: number; screenY: number; shiftKey: boolean; } interface TouchEvent extends SyntheticEvent { altKey: boolean; changedTouches: TouchList; ctrlKey: boolean; getModifierState(key: string): boolean; metaKey: boolean; shiftKey: boolean; targetTouches: TouchList; touches: TouchList; } interface UIEvent extends SyntheticEvent { detail: number; view: AbstractView; } interface WheelEvent extends SyntheticEvent { deltaMode: number; deltaX: number; deltaY: number; deltaZ: number; } // // Event Handler Types // ---------------------------------------------------------------------- interface EventHandler { (event: E): void; } type ReactEventHandler = EventHandler; type ClipboardEventHandler = EventHandler; type CompositionEventHandler = EventHandler; type DragEventHandler = EventHandler; type FocusEventHandler = EventHandler; type FormEventHandler = EventHandler; type KeyboardEventHandler = EventHandler; type MouseEventHandler = EventHandler; type TouchEventHandler = EventHandler; type UIEventHandler = EventHandler; type WheelEventHandler = EventHandler; // // Props / DOM Attributes // ---------------------------------------------------------------------- /** * @deprecated. This was used to allow clients to pass `ref` and `key` * to `createElement`, which is no longer necessary due to intersection * types. If you need to declare a props object before passing it to * `createElement` or a factory, use `ClassAttributes`: * * ```ts * var b: Button; * var props: ButtonProps & ClassAttributes