4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | declare module 'react' {
7 | interface ComponentClass {
8 | new(props: P): Component;
9 | }
10 | //
11 | // Component
12 | // ----------------------------------------------------------------------
13 |
14 | class Component {
15 | constructor(initialProps: P);
16 |
17 | public getDOMNode(): Element;
18 | public isMounted(): boolean;
19 |
20 |
21 | props: P;
22 |
23 | protected setProps(nextProps: P, callback?: () => void): void;
24 | protected replaceProps(nextProps: P, callback?: () => void): void;
25 |
26 | state: S;
27 | protected setState(nextState: S, callback?: () => void): void;
28 | protected replaceState(nextState: S, callback?: () => void): void;
29 |
30 | protected context: any; // I won't introduce a third generic type for that sorry
31 |
32 |
33 | protected render(): ReactElement | string;
34 |
35 |
36 | protected componentWillMount(): void;
37 | protected componentDidMount(): void;
38 | protected componentWillReceiveProps(nextProps: P): void;
39 | protected shouldComponentUpdate(nextProps: P, nextState: S): boolean;
40 | protected componentWillUpdate(nextProps: P, nextState: S): void;
41 | protected componentDidUpdate(prevProps: P, prevState: S): void;
42 | protected componentWillUnmount(): void;
43 |
44 |
45 | static defaultProps: any;
46 | static propTypes: ValidationMap;
47 | static contextTypes: ValidationMap;
48 | static childContextTypes: ValidationMap;
49 | }
50 |
51 | //
52 | // ReactElement
53 | // ----------------------------------------------------------------------
54 |
55 |
56 |
57 | interface ReactCompositeElement {
58 | type: ComponentClass
59 | ref: (c: Component) => any;
60 | key : string | boolean | number;
61 | props: P;
62 | }
63 |
64 | interface ReactHTMLElement {
65 | type: string;
66 | ref: (c: Component) => any;
67 | key : string | boolean | number;
68 | props: HTMLAttributes;
69 | }
70 |
71 | interface ReactSVGElement {
72 | type: string;
73 | ref: (c: Component) => any;
74 | key : string | boolean | number;
75 | props: SVGAttributes;
76 | }
77 |
78 | type ReactElement = ReactHTMLElement | ReactSVGElement | ReactCompositeElement;
79 |
80 | interface ReactElementArray extends Array {}
81 |
82 |
83 | function createElement(type: string, props: HTMLAttributes, ...children: any[]): ReactHTMLElement;
84 | function createElement(type: string, props: SVGAttributes, ...children: any[]): ReactSVGElement;
85 | function createElement(type: ComponentClass
, props: P, ...children: any[]): ReactCompositeElement
86 |
87 |
88 |
89 | //
90 | // Event System
91 | // ----------------------------------------------------------------------
92 |
93 | interface SyntheticEvent {
94 | bubbles: boolean;
95 | cancelable: boolean;
96 | currentTarget: EventTarget;
97 | defaultPrevented: boolean;
98 | eventPhase: number;
99 | isTrusted: boolean;
100 | nativeEvent: Event;
101 | preventDefault(): void;
102 | stopPropagation(): void;
103 | target: EventTarget;
104 | timeStamp: Date;
105 | type: string;
106 | }
107 |
108 | interface ClipboardEvent extends SyntheticEvent {
109 | clipboardData: DataTransfer;
110 | }
111 |
112 | interface KeyboardEvent extends SyntheticEvent {
113 | altKey: boolean;
114 | charCode: number;
115 | ctrlKey: boolean;
116 | getModifierState(key: string): boolean;
117 | key: string;
118 | keyCode: number;
119 | locale: string;
120 | location: number;
121 | metaKey: boolean;
122 | repeat: boolean;
123 | shiftKey: boolean;
124 | which: number;
125 | }
126 |
127 | interface FocusEvent extends SyntheticEvent {
128 | relatedTarget: EventTarget;
129 | }
130 |
131 | interface FormEvent extends SyntheticEvent {
132 | }
133 |
134 | interface MouseEvent extends SyntheticEvent {
135 | altKey: boolean;
136 | button: number;
137 | buttons: number;
138 | clientX: number;
139 | clientY: number;
140 | ctrlKey: boolean;
141 | getModifierState(key: string): boolean;
142 | metaKey: boolean;
143 | pageX: number;
144 | pageY: number;
145 | relatedTarget: EventTarget;
146 | screenX: number;
147 | screenY: number;
148 | shiftKey: boolean;
149 | }
150 |
151 | interface TouchEvent extends SyntheticEvent {
152 | altKey: boolean;
153 | changedTouches: TouchList;
154 | ctrlKey: boolean;
155 | getModifierState(key: string): boolean;
156 | metaKey: boolean;
157 | shiftKey: boolean;
158 | targetTouches: TouchList;
159 | touches: TouchList;
160 | }
161 |
162 | interface UIEvent extends SyntheticEvent {
163 | detail: number;
164 | view: AbstractView;
165 | }
166 |
167 | interface WheelEvent extends SyntheticEvent {
168 | deltaMode: number;
169 | deltaX: number;
170 | deltaY: number;
171 | deltaZ: number;
172 | }
173 |
174 | //
175 | // Event Handler Types
176 | // ----------------------------------------------------------------------
177 |
178 | interface EventHandler {
179 | (event: E): void;
180 | }
181 |
182 | interface ClipboardEventHandler extends EventHandler {}
183 | interface KeyboardEventHandler extends EventHandler {}
184 | interface FocusEventHandler extends EventHandler {}
185 | interface FormEventHandler extends EventHandler {}
186 | interface MouseEventHandler extends EventHandler {}
187 | interface TouchEventHandler extends EventHandler {}
188 | interface UIEventHandler extends EventHandler {}
189 | interface WheelEventHandler extends EventHandler {}
190 |
191 |
192 | //
193 | // Attributes
194 | // ----------------------------------------------------------------------
195 |
196 | interface BaseProps {
197 | children?: string | ReactElement | ReactElementArray;
198 | key?: string;
199 | ref?: (c: Component) => void
200 | }
201 |
202 |
203 | interface ReactBaseElementAttributes extends BaseProps {
204 | // Event Attributes
205 | onCopy?: ClipboardEventHandler;
206 | onCut?: ClipboardEventHandler;
207 | onPaste?: ClipboardEventHandler;
208 | onKeyDown?: KeyboardEventHandler;
209 | onKeyPress?: KeyboardEventHandler;
210 | onKeyUp?: KeyboardEventHandler;
211 | onFocus?: FocusEventHandler;
212 | onBlur?: FocusEventHandler;
213 | onChange?: FormEventHandler;
214 | onInput?: FormEventHandler;
215 | onSubmit?: FormEventHandler;
216 | onClick?: MouseEventHandler;
217 | onDoubleClick?: MouseEventHandler;
218 | onDrag?: MouseEventHandler;
219 | onDragEnd?: MouseEventHandler;
220 | onDragEnter?: MouseEventHandler;
221 | onDragExit?: MouseEventHandler;
222 | onDragLeave?: MouseEventHandler;
223 | onDragOver?: MouseEventHandler;
224 | onDragStart?: MouseEventHandler;
225 | onDrop?: MouseEventHandler;
226 | onMouseDown?: MouseEventHandler;
227 | onMouseEnter?: MouseEventHandler;
228 | onMouseLeave?: MouseEventHandler;
229 | onMouseMove?: MouseEventHandler;
230 | onMouseOut?: MouseEventHandler;
231 | onMouseOver?: MouseEventHandler;
232 | onMouseUp?: MouseEventHandler;
233 | onTouchCancel?: TouchEventHandler;
234 | onTouchEnd?: TouchEventHandler;
235 | onTouchMove?: TouchEventHandler;
236 | onTouchStart?: TouchEventHandler;
237 | onScroll?: UIEventHandler;
238 | onWheel?: WheelEventHandler;
239 |
240 | dangerouslySetInnerHTML?: {
241 | __html: string;
242 | };
243 | }
244 |
245 | interface CSSProperties {
246 | columnCount?: number;
247 | flex?: number | string;
248 | flexGrow?: number;
249 | flexShrink?: number;
250 | fontWeight?: number;
251 | lineClamp?: number;
252 | lineHeight?: number;
253 | opacity?: number;
254 | order?: number;
255 | orphans?: number;
256 | widows?: number;
257 | zIndex?: number;
258 | zoom?: number;
259 |
260 | // SVG-related properties
261 | fillOpacity?: number;
262 | strokeOpacity?: number;
263 | }
264 |
265 | interface HTMLAttributes extends ReactBaseElementAttributes {
266 | accept?: string;
267 | acceptCharset?: string;
268 | accessKey?: string;
269 | action?: string;
270 | allowFullScreen?: boolean;
271 | allowTransparency?: boolean;
272 | alt?: string;
273 | async?: boolean;
274 | autoComplete?: boolean;
275 | autoFocus?: boolean;
276 | autoPlay?: boolean;
277 | cellPadding?: number | string;
278 | cellSpacing?: number | string;
279 | charSet?: string;
280 | checked?: boolean;
281 | classID?: string;
282 | className?: string;
283 | cols?: number;
284 | colSpan?: number;
285 | content?: string;
286 | contentEditable?: boolean;
287 | contextMenu?: string;
288 | controls?: any;
289 | coords?: string;
290 | crossOrigin?: string;
291 | data?: string;
292 | dateTime?: string;
293 | defer?: boolean;
294 | dir?: string;
295 | disabled?: boolean;
296 | download?: any;
297 | draggable?: boolean;
298 | encType?: string;
299 | form?: string;
300 | formNoValidate?: boolean;
301 | frameBorder?: number | string;
302 | height?: number | string;
303 | hidden?: boolean;
304 | href?: string;
305 | hrefLang?: string;
306 | htmlFor?: string;
307 | httpEquiv?: string;
308 | icon?: string;
309 | id?: string;
310 | label?: string;
311 | lang?: string;
312 | list?: string;
313 | loop?: boolean;
314 | manifest?: string;
315 | max?: number | string;
316 | maxLength?: number;
317 | media?: string;
318 | mediaGroup?: string;
319 | method?: string;
320 | min?: number | string;
321 | multiple?: boolean;
322 | muted?: boolean;
323 | name?: string;
324 | noValidate?: boolean;
325 | open?: boolean;
326 | pattern?: string;
327 | placeholder?: string;
328 | poster?: string;
329 | preload?: string;
330 | radioGroup?: string;
331 | readOnly?: boolean;
332 | rel?: string;
333 | required?: boolean;
334 | role?: string;
335 | rows?: number;
336 | rowSpan?: number;
337 | sandbox?: string;
338 | scope?: string;
339 | scrollLeft?: number;
340 | scrolling?: string;
341 | scrollTop?: number;
342 | seamless?: boolean;
343 | selected?: boolean;
344 | shape?: string;
345 | size?: number;
346 | sizes?: string;
347 | span?: number;
348 | spellCheck?: boolean;
349 | src?: string;
350 | srcDoc?: string;
351 | srcSet?: string;
352 | start?: number;
353 | step?: number | string;
354 | style?: CSSProperties;
355 | tabIndex?: number;
356 | target?: string;
357 | title?: string;
358 | type?: string;
359 | useMap?: string;
360 | value?: string;
361 | width?: number | string;
362 | wmode?: string;
363 |
364 | // Non-standard Attributes
365 | autoCapitalize?: boolean;
366 | autoCorrect?: boolean;
367 | property?: string;
368 | itemProp?: string;
369 | itemScope?: boolean;
370 | itemType?: string;
371 | }
372 |
373 | interface SVGAttributes extends ReactBaseElementAttributes {
374 | cx?: SVGLength | SVGAnimatedLength;
375 | cy?: any;
376 | d?: string;
377 | dx?: SVGLength | SVGAnimatedLength;
378 | dy?: SVGLength | SVGAnimatedLength;
379 | fill?: any; // SVGPaint | string
380 | fillOpacity?: number | string;
381 | fontFamily?: string;
382 | fontSize?: number | string;
383 | fx?: SVGLength | SVGAnimatedLength;
384 | fy?: SVGLength | SVGAnimatedLength;
385 | gradientTransform?: SVGTransformList | SVGAnimatedTransformList;
386 | gradientUnits?: string;
387 | markerEnd?: string;
388 | markerMid?: string;
389 | markerStart?: string;
390 | offset?: number | string;
391 | opacity?: number | string;
392 | patternContentUnits?: string;
393 | patternUnits?: string;
394 | points?: string;
395 | preserveAspectRatio?: string;
396 | r?: SVGLength | SVGAnimatedLength;
397 | rx?: SVGLength | SVGAnimatedLength;
398 | ry?: SVGLength | SVGAnimatedLength;
399 | spreadMethod?: string;
400 | stopColor?: any; // SVGColor | string
401 | stopOpacity?: number | string;
402 | stroke?: any; // SVGPaint
403 | strokeDasharray?: string;
404 | strokeLinecap?: string;
405 | strokeOpacity?: number | string;
406 | strokeWidth?: SVGLength | SVGAnimatedLength;
407 | textAnchor?: string;
408 | transform?: SVGTransformList | SVGAnimatedTransformList;
409 | version?: string;
410 | viewBox?: string;
411 | x1?: SVGLength | SVGAnimatedLength;
412 | x2?: SVGLength | SVGAnimatedLength;
413 | x?: SVGLength | SVGAnimatedLength;
414 | y1?: SVGLength | SVGAnimatedLength;
415 | y2?: SVGLength | SVGAnimatedLength
416 | y?: SVGLength | SVGAnimatedLength;
417 | }
418 |
419 |
420 | //
421 | // Browser Interfaces
422 | // https://github.com/nikeee/2048-typescript/blob/master/2048/js/touch.d.ts
423 | // ----------------------------------------------------------------------
424 |
425 | interface AbstractView {
426 | styleMedia: StyleMedia;
427 | document: Document;
428 | }
429 |
430 | interface Touch {
431 | identifier: number;
432 | target: EventTarget;
433 | screenX: number;
434 | screenY: number;
435 | clientX: number;
436 | clientY: number;
437 | pageX: number;
438 | pageY: number;
439 | }
440 |
441 | interface TouchList {
442 | [index: number]: Touch;
443 | length: number;
444 | item(index: number): Touch;
445 | identifiedTouch(identifier: number): Touch;
446 | }
447 |
448 |
449 |
450 | //
451 | // React.PropTypes
452 | // ----------------------------------------------------------------------
453 |
454 | interface Validator {
455 | (object: T, key: string, componentName: string): Error;
456 | }
457 |
458 | interface Requireable extends Validator {
459 | isRequired: Validator;
460 | }
461 |
462 | interface ValidationMap {
463 | [key: string]: Validator;
464 | }
465 |
466 | var PropTypes: {
467 | any: Requireable;
468 | array: Requireable;
469 | bool: Requireable;
470 | func: Requireable;
471 | number: Requireable;
472 | object: Requireable;
473 | string: Requireable;
474 | node: Requireable;
475 | element: Requireable;
476 | instanceOf(expectedClass: {}): Requireable;
477 | oneOf(types: any[]): Requireable;
478 | oneOfType(types: Validator[]): Requireable;
479 | arrayOf(type: Validator): Requireable;
480 | objectOf(type: Validator): Requireable;
481 | shape(type: ValidationMap): Requireable;
482 | }
483 |
484 | //
485 | // React.Children
486 | // ----------------------------------------------------------------------
487 |
488 | type ReactChild = string | ReactElement;
489 | type ReactChildList = string | ReactElement | ReactElementArray
490 |
491 | interface ReactChildren {
492 | map(children: ReactElementArray, fn: (child: ReactChild) => T): Array;
493 | forEach(children: ReactElementArray, fn: (child: ReactChild) => any): void;
494 | count(children: ReactElementArray): number;
495 | only(children: ReactElementArray): ReactChild;
496 | }
497 |
498 |
499 | function render(element: ReactElement, container: Element, callback?: () => void): Component;
500 | function renderToString(element: ReactElement): string;
501 | function renderToStaticMarkup(element: ReactElement): string;
502 | function isValidElement(element: any): boolean;
503 | function unmountComponentAtNode(container: Element): boolean;
504 | function initializeTouchEvents(shouldUseTouch: boolean): void;
505 |
506 | }
507 |
--------------------------------------------------------------------------------