From ffedf917dfd05d37b45a07ccaf2eea4488e629c7 Mon Sep 17 00:00:00 2001 From: Vincent Siao Date: Sat, 14 Mar 2015 15:27:46 -0700 Subject: [PATCH 1/5] Remove beta and RC2 references from React defs --- react/README.md | 2 +- react/react-addons-global.d.ts | 2 +- react/react-addons.d.ts | 2 +- react/react-global.d.ts | 2 +- react/react.d.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/react/README.md b/react/README.md index 07a203920..0c773fd38 100644 --- a/react/README.md +++ b/react/README.md @@ -1,4 +1,4 @@ -# React v0.13.0-beta Type Definitions +# React v0.13.0 Type Definitions This folder contains the following `.d.ts` files: * `react-0.13.0.d.ts` declares the external module `"react"` diff --git a/react/react-addons-global.d.ts b/react/react-addons-global.d.ts index c50ecdc21..bb0013276 100644 --- a/react/react-addons-global.d.ts +++ b/react/react-addons-global.d.ts @@ -1,4 +1,4 @@ -// Type definitions for ReactWithAddons v0.13.0 RC2 (internal module) +// Type definitions for ReactWithAddons v0.13.0 (internal module) // Project: http://facebook.github.io/react/ // Definitions by: Asana , AssureSign // Definitions: https://github.com/borisyankov/DefinitelyTyped diff --git a/react/react-addons.d.ts b/react/react-addons.d.ts index 19cf44ed2..be6f1cff0 100644 --- a/react/react-addons.d.ts +++ b/react/react-addons.d.ts @@ -1,4 +1,4 @@ -// Type definitions for ReactWithAddons v0.13.0 RC2 (external module) +// Type definitions for ReactWithAddons v0.13.0 (external module) // Project: http://facebook.github.io/react/ // Definitions by: Asana , AssureSign // Definitions: https://github.com/borisyankov/DefinitelyTyped diff --git a/react/react-global.d.ts b/react/react-global.d.ts index 268d4bf86..c74e2364a 100644 --- a/react/react-global.d.ts +++ b/react/react-global.d.ts @@ -1,4 +1,4 @@ -// Type definitions for React v0.13.0 RC2 (internal module) +// Type definitions for React v0.13.0 (internal module) // Project: http://facebook.github.io/react/ // Definitions by: Asana , AssureSign // Definitions: https://github.com/borisyankov/DefinitelyTyped diff --git a/react/react.d.ts b/react/react.d.ts index 114938808..232d75c70 100644 --- a/react/react.d.ts +++ b/react/react.d.ts @@ -1,4 +1,4 @@ -// Type definitions for React v0.13.0 RC2 (external module) +// Type definitions for React v0.13.0 (external module) // Project: http://facebook.github.io/react/ // Definitions by: Asana , AssureSign // Definitions: https://github.com/borisyankov/DefinitelyTyped From 0213f7c10e966718f4690d2408aeca6753247f09 Mon Sep 17 00:00:00 2001 From: Vincent Siao Date: Sat, 14 Mar 2015 15:28:48 -0700 Subject: [PATCH 2/5] Fix state initializers in react-tests.ts (Fixes #3855) --- react/react-addons-tests.ts | 2 +- react/react-tests.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/react/react-addons-tests.ts b/react/react-addons-tests.ts index 9bd3d5505..725edd056 100644 --- a/react/react-addons-tests.ts +++ b/react/react-addons-tests.ts @@ -324,7 +324,7 @@ interface TimerState { secondsElapsed: number; } class Timer extends React.Component, TimerState> { - static state = { + state = { secondsElapsed: 0 } private _interval: number; diff --git a/react/react-tests.ts b/react/react-tests.ts index a9b693cab..c6f186e8b 100644 --- a/react/react-tests.ts +++ b/react/react-tests.ts @@ -324,7 +324,7 @@ interface TimerState { secondsElapsed: number; } class Timer extends React.Component<{}, TimerState> { - static state = { + state = { secondsElapsed: 0 } private _interval: number; @@ -334,8 +334,7 @@ class Timer extends React.Component<{}, TimerState> { })); } componentDidMount() { - var me = this; - this._interval = setInterval(() => me.tick(), 1000); + this._interval = setInterval(() => this.tick(), 1000); } componentWillUnmount() { clearInterval(this._interval); From d3584fa71661cfb0b320646af621c74db5706f81 Mon Sep 17 00:00:00 2001 From: Vincent Siao Date: Sat, 14 Mar 2015 15:29:37 -0700 Subject: [PATCH 3/5] Add ReactShallowRenderer types See http://facebook.github.io/react/docs/test-utils.html#shallow-rendering --- react/react-addons-global.d.ts | 8 ++++++++ react/react-addons-tests.ts | 5 +++++ react/react-addons.d.ts | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/react/react-addons-global.d.ts b/react/react-addons-global.d.ts index bb0013276..5a6608dbb 100644 --- a/react/react-addons-global.d.ts +++ b/react/react-addons-global.d.ts @@ -179,6 +179,8 @@ declare module React { findRenderedComponentWithType>( tree: Component, type: ComponentClass): C; + + createRenderer(): ShallowRenderer; } interface SyntheticEventData { @@ -255,5 +257,11 @@ declare module React { touchStart: EventSimulator; wheel: EventSimulator; } + + class ShallowRenderer { + getRenderOutput>(): C; + render(element: ReactElement, context?: any): void; + unmount(): void; + } } diff --git a/react/react-addons-tests.ts b/react/react-addons-tests.ts index 725edd056..d53086d69 100644 --- a/react/react-addons-tests.ts +++ b/react/react-addons-tests.ts @@ -387,3 +387,8 @@ React.addons.TestUtils.Simulate.click(node); React.addons.TestUtils.Simulate.change(node); React.addons.TestUtils.Simulate.keyDown(node, { key: "Enter" }); +var renderer: React.ShallowRenderer = + React.addons.TestUtils.createRenderer(); +renderer.render(React.createElement(Timer)); +var output: Timer = renderer.getRenderOutput(); + diff --git a/react/react-addons.d.ts b/react/react-addons.d.ts index be6f1cff0..95bb5ecf5 100644 --- a/react/react-addons.d.ts +++ b/react/react-addons.d.ts @@ -904,6 +904,8 @@ declare module "react/addons" { findRenderedComponentWithType>( tree: Component, type: ComponentClass): C; + + createRenderer(): ShallowRenderer; } interface SyntheticEventData { @@ -981,6 +983,12 @@ declare module "react/addons" { wheel: EventSimulator; } + class ShallowRenderer { + getRenderOutput>(): C; + render(element: ReactElement, context?: any): void; + unmount(): void; + } + // // Browser Interfaces // https://github.com/nikeee/2048-typescript/blob/master/2048/js/touch.d.ts From 424bb99eacf566a103c66e73aeb94aff43a80c1b Mon Sep 17 00:00:00 2001 From: Vincent Siao Date: Sat, 14 Mar 2015 16:15:59 -0700 Subject: [PATCH 4/5] Don't use DOM API interfaces for React.SVGAttributes --- react/react-addons-tests.ts | 14 ++++++++++ react/react-addons.d.ts | 51 ++++++++++++++++++++----------------- react/react-global.d.ts | 51 ++++++++++++++++++++----------------- react/react-tests.ts | 15 +++++++++++ react/react.d.ts | 51 ++++++++++++++++++++----------------- 5 files changed, 113 insertions(+), 69 deletions(-) diff --git a/react/react-addons-tests.ts b/react/react-addons-tests.ts index d53086d69..72d6db486 100644 --- a/react/react-addons-tests.ts +++ b/react/react-addons-tests.ts @@ -224,6 +224,20 @@ React.DOM.div(htmlAttr); React.DOM.span(htmlAttr); React.DOM.input(htmlAttr); +React.DOM.svg({ viewBox: "0 0 48 48" }, + React.DOM.rect({ + x: 22, + y: 10, + width: 4, + height: 28 + }), + React.DOM.rect({ + x: 10, + y: 22, + width: 28, + height: 4 + })); + // // React.PropTypes // -------------------------------------------------------------------------- diff --git a/react/react-addons.d.ts b/react/react-addons.d.ts index 95bb5ecf5..c09f5f641 100644 --- a/react/react-addons.d.ts +++ b/react/react-addons.d.ts @@ -368,14 +368,18 @@ declare module "react/addons" { }; } + // This interface is not complete. Only properties accepting + // unitless numbers are listed here (see CSSProperty.js in React) interface CSSProperties { + boxFlex?: number; + boxFlexGroup?: number; columnCount?: number; flex?: number | string; flexGrow?: number; flexShrink?: number; - fontWeight?: number; + fontWeight?: number | string; lineClamp?: number; - lineHeight?: number; + lineHeight?: number | string; opacity?: number; order?: number; orphans?: number; @@ -386,6 +390,7 @@ declare module "react/addons" { // SVG-related properties fillOpacity?: number; strokeOpacity?: number; + strokeWidth?: number; } interface HTMLAttributes extends DOMAttributes { @@ -501,18 +506,18 @@ declare module "react/addons" { interface SVGAttributes extends DOMAttributes { ref?: string | ((component: SVGComponent) => void); - cx?: SVGLength | SVGAnimatedLength; - cy?: any; + cx?: number | string; + cy?: number | string; d?: string; - dx?: SVGLength | SVGAnimatedLength; - dy?: SVGLength | SVGAnimatedLength; - fill?: any; // SVGPaint | string + dx?: number | string; + dy?: number | string; + fill?: string; fillOpacity?: number | string; fontFamily?: string; fontSize?: number | string; - fx?: SVGLength | SVGAnimatedLength; - fy?: SVGLength | SVGAnimatedLength; - gradientTransform?: SVGTransformList | SVGAnimatedTransformList; + fx?: number | string; + fy?: number | string; + gradientTransform?: string; gradientUnits?: string; markerEnd?: string; markerMid?: string; @@ -523,27 +528,27 @@ declare module "react/addons" { patternUnits?: string; points?: string; preserveAspectRatio?: string; - r?: SVGLength | SVGAnimatedLength; - rx?: SVGLength | SVGAnimatedLength; - ry?: SVGLength | SVGAnimatedLength; + r?: number | string; + rx?: number | string; + ry?: number | string; spreadMethod?: string; - stopColor?: any; // SVGColor | string + stopColor?: string; stopOpacity?: number | string; - stroke?: any; // SVGPaint + stroke?: string; strokeDasharray?: string; strokeLinecap?: string; strokeOpacity?: number | string; - strokeWidth?: SVGLength | SVGAnimatedLength; + strokeWidth?: number | string; textAnchor?: string; - transform?: SVGTransformList | SVGAnimatedTransformList; + transform?: string; version?: string; viewBox?: string; - x1?: SVGLength | SVGAnimatedLength; - x2?: SVGLength | SVGAnimatedLength; - x?: SVGLength | SVGAnimatedLength; - y1?: SVGLength | SVGAnimatedLength; - y2?: SVGLength | SVGAnimatedLength - y?: SVGLength | SVGAnimatedLength; + x1?: number | string; + x2?: number | string; + x?: number | string; + y1?: number | string; + y2?: number | string + y?: number | string; } // diff --git a/react/react-global.d.ts b/react/react-global.d.ts index c74e2364a..2b3a58523 100644 --- a/react/react-global.d.ts +++ b/react/react-global.d.ts @@ -368,14 +368,18 @@ declare module React { }; } + // This interface is not complete. Only properties accepting + // unitless numbers are listed here (see CSSProperty.js in React) interface CSSProperties { + boxFlex?: number; + boxFlexGroup?: number; columnCount?: number; flex?: number | string; flexGrow?: number; flexShrink?: number; - fontWeight?: number; + fontWeight?: number | string; lineClamp?: number; - lineHeight?: number; + lineHeight?: number | string; opacity?: number; order?: number; orphans?: number; @@ -386,6 +390,7 @@ declare module React { // SVG-related properties fillOpacity?: number; strokeOpacity?: number; + strokeWidth?: number; } interface HTMLAttributes extends DOMAttributes { @@ -501,18 +506,18 @@ declare module React { interface SVGAttributes extends DOMAttributes { ref?: string | ((component: SVGComponent) => void); - cx?: SVGLength | SVGAnimatedLength; - cy?: any; + cx?: number | string; + cy?: number | string; d?: string; - dx?: SVGLength | SVGAnimatedLength; - dy?: SVGLength | SVGAnimatedLength; - fill?: any; // SVGPaint | string + dx?: number | string; + dy?: number | string; + fill?: string; fillOpacity?: number | string; fontFamily?: string; fontSize?: number | string; - fx?: SVGLength | SVGAnimatedLength; - fy?: SVGLength | SVGAnimatedLength; - gradientTransform?: SVGTransformList | SVGAnimatedTransformList; + fx?: number | string; + fy?: number | string; + gradientTransform?: string; gradientUnits?: string; markerEnd?: string; markerMid?: string; @@ -523,27 +528,27 @@ declare module React { patternUnits?: string; points?: string; preserveAspectRatio?: string; - r?: SVGLength | SVGAnimatedLength; - rx?: SVGLength | SVGAnimatedLength; - ry?: SVGLength | SVGAnimatedLength; + r?: number | string; + rx?: number | string; + ry?: number | string; spreadMethod?: string; - stopColor?: any; // SVGColor | string + stopColor?: string; stopOpacity?: number | string; - stroke?: any; // SVGPaint + stroke?: string; strokeDasharray?: string; strokeLinecap?: string; strokeOpacity?: number | string; - strokeWidth?: SVGLength | SVGAnimatedLength; + strokeWidth?: number | string; textAnchor?: string; - transform?: SVGTransformList | SVGAnimatedTransformList; + transform?: string; version?: string; viewBox?: string; - x1?: SVGLength | SVGAnimatedLength; - x2?: SVGLength | SVGAnimatedLength; - x?: SVGLength | SVGAnimatedLength; - y1?: SVGLength | SVGAnimatedLength; - y2?: SVGLength | SVGAnimatedLength - y?: SVGLength | SVGAnimatedLength; + x1?: number | string; + x2?: number | string; + x?: number | string; + y1?: number | string; + y2?: number | string + y?: number | string; } // diff --git a/react/react-tests.ts b/react/react-tests.ts index c6f186e8b..2802a34cd 100644 --- a/react/react-tests.ts +++ b/react/react-tests.ts @@ -224,6 +224,21 @@ React.DOM.div(htmlAttr); React.DOM.span(htmlAttr); React.DOM.input(htmlAttr); +React.DOM.svg({ viewBox: "0 0 48 48" }, + React.DOM.rect({ + x: 22, + y: 10, + width: 4, + height: 28 + }), + React.DOM.rect({ + x: 10, + y: 22, + width: 28, + height: 4 + })); + + // // React.PropTypes // -------------------------------------------------------------------------- diff --git a/react/react.d.ts b/react/react.d.ts index 232d75c70..c0d065167 100644 --- a/react/react.d.ts +++ b/react/react.d.ts @@ -368,14 +368,18 @@ declare module "react" { }; } + // This interface is not complete. Only properties accepting + // unitless numbers are listed here (see CSSProperty.js in React) interface CSSProperties { + boxFlex?: number; + boxFlexGroup?: number; columnCount?: number; flex?: number | string; flexGrow?: number; flexShrink?: number; - fontWeight?: number; + fontWeight?: number | string; lineClamp?: number; - lineHeight?: number; + lineHeight?: number | string; opacity?: number; order?: number; orphans?: number; @@ -386,6 +390,7 @@ declare module "react" { // SVG-related properties fillOpacity?: number; strokeOpacity?: number; + strokeWidth?: number; } interface HTMLAttributes extends DOMAttributes { @@ -501,18 +506,18 @@ declare module "react" { interface SVGAttributes extends DOMAttributes { ref?: string | ((component: SVGComponent) => void); - cx?: SVGLength | SVGAnimatedLength; - cy?: any; + cx?: number | string; + cy?: number | string; d?: string; - dx?: SVGLength | SVGAnimatedLength; - dy?: SVGLength | SVGAnimatedLength; - fill?: any; // SVGPaint | string + dx?: number | string; + dy?: number | string; + fill?: string; fillOpacity?: number | string; fontFamily?: string; fontSize?: number | string; - fx?: SVGLength | SVGAnimatedLength; - fy?: SVGLength | SVGAnimatedLength; - gradientTransform?: SVGTransformList | SVGAnimatedTransformList; + fx?: number | string; + fy?: number | string; + gradientTransform?: string; gradientUnits?: string; markerEnd?: string; markerMid?: string; @@ -523,27 +528,27 @@ declare module "react" { patternUnits?: string; points?: string; preserveAspectRatio?: string; - r?: SVGLength | SVGAnimatedLength; - rx?: SVGLength | SVGAnimatedLength; - ry?: SVGLength | SVGAnimatedLength; + r?: number | string; + rx?: number | string; + ry?: number | string; spreadMethod?: string; - stopColor?: any; // SVGColor | string + stopColor?: string; stopOpacity?: number | string; - stroke?: any; // SVGPaint + stroke?: string; strokeDasharray?: string; strokeLinecap?: string; strokeOpacity?: number | string; - strokeWidth?: SVGLength | SVGAnimatedLength; + strokeWidth?: number | string; textAnchor?: string; - transform?: SVGTransformList | SVGAnimatedTransformList; + transform?: string; version?: string; viewBox?: string; - x1?: SVGLength | SVGAnimatedLength; - x2?: SVGLength | SVGAnimatedLength; - x?: SVGLength | SVGAnimatedLength; - y1?: SVGLength | SVGAnimatedLength; - y2?: SVGLength | SVGAnimatedLength - y?: SVGLength | SVGAnimatedLength; + x1?: number | string; + x2?: number | string; + x?: number | string; + y1?: number | string; + y2?: number | string + y?: number | string; } // From b35ac04569bc1fefa0bed0886c553c91afb6bf7f Mon Sep 17 00:00:00 2001 From: Vincent Siao Date: Wed, 18 Mar 2015 09:46:36 -0700 Subject: [PATCH 5/5] React 0.13.0->0.13.1 and make arguments to Component constructor optional --- react/react-addons-global.d.ts | 2 +- react/react-addons.d.ts | 4 ++-- react/react-global.d.ts | 4 ++-- react/react.d.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/react/react-addons-global.d.ts b/react/react-addons-global.d.ts index 5a6608dbb..891e0d101 100644 --- a/react/react-addons-global.d.ts +++ b/react/react-addons-global.d.ts @@ -1,4 +1,4 @@ -// Type definitions for ReactWithAddons v0.13.0 (internal module) +// Type definitions for ReactWithAddons v0.13.1 (internal module) // Project: http://facebook.github.io/react/ // Definitions by: Asana , AssureSign // Definitions: https://github.com/borisyankov/DefinitelyTyped diff --git a/react/react-addons.d.ts b/react/react-addons.d.ts index c09f5f641..54fce3ada 100644 --- a/react/react-addons.d.ts +++ b/react/react-addons.d.ts @@ -1,4 +1,4 @@ -// Type definitions for ReactWithAddons v0.13.0 (external module) +// Type definitions for ReactWithAddons v0.13.1 (external module) // Project: http://facebook.github.io/react/ // Definitions by: Asana , AssureSign // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -131,7 +131,7 @@ declare module "react/addons" { // Base component for plain JS classes class Component implements ComponentLifecycle { - constructor(props: P, context: any); + constructor(props?: P, context?: any); setState(f: (prevState: S, props: P) => S, callback?: () => any): void; setState(state: S, callback?: () => any): void; forceUpdate(): void; diff --git a/react/react-global.d.ts b/react/react-global.d.ts index 2b3a58523..f7b7859d4 100644 --- a/react/react-global.d.ts +++ b/react/react-global.d.ts @@ -1,4 +1,4 @@ -// Type definitions for React v0.13.0 (internal module) +// Type definitions for React v0.13.1 (internal module) // Project: http://facebook.github.io/react/ // Definitions by: Asana , AssureSign // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -131,7 +131,7 @@ declare module React { // Base component for plain JS classes class Component implements ComponentLifecycle { - constructor(props: P, context: any); + constructor(props?: P, context?: any); setState(f: (prevState: S, props: P) => S, callback?: () => any): void; setState(state: S, callback?: () => any): void; forceUpdate(): void; diff --git a/react/react.d.ts b/react/react.d.ts index c0d065167..64796ddf4 100644 --- a/react/react.d.ts +++ b/react/react.d.ts @@ -1,4 +1,4 @@ -// Type definitions for React v0.13.0 (external module) +// Type definitions for React v0.13.1 (external module) // Project: http://facebook.github.io/react/ // Definitions by: Asana , AssureSign // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -131,7 +131,7 @@ declare module "react" { // Base component for plain JS classes class Component implements ComponentLifecycle { - constructor(props: P, context: any); + constructor(props?: P, context?: any); setState(f: (prevState: S, props: P) => S, callback?: () => any): void; setState(state: S, callback?: () => any): void; forceUpdate(): void;