diff --git a/react/react-tests.ts b/react/react-tests.ts index 338e483a0..07c8a89d4 100644 --- a/react/react-tests.ts +++ b/react/react-tests.ts @@ -193,9 +193,7 @@ var childMap: { [key: string]: number } = React.Children.map(children, (child) => { return 42; }); React.Children.forEach(children, (child) => {}); var nChildren: number = React.Children.count(children); -var onlyChild = React.Children.only([null, [[["Hallo"], true]], false, { - test: null -}]); +var onlyChild = React.Children.only([null, [[["Hallo"], true]], false]); // // Example from http://facebook.github.io/react/ diff --git a/react/react.d.ts b/react/react.d.ts index 2b75bb3fd..f2786cbc8 100644 --- a/react/react.d.ts +++ b/react/react.d.ts @@ -8,12 +8,12 @@ declare module React { // React Elements // ---------------------------------------------------------------------- - // type ReactType = ComponentClass | string; + type ReactType = ComponentClass | string; interface ReactElement

{ - type: any; // ReactType + type: ComponentClass

| string; props: P; - key: any; // number | string + key: number | string; ref: string; } @@ -22,14 +22,15 @@ declare module React { // // React Nodes + // http://facebook.github.io/react/docs/glossary.html // ---------------------------------------------------------------------- - // type ReactText = string | number; - // type Fragment = ReactNode[]; - // type ReactNode = ReactElement | Fragment | ReactText | KeyMap; - // interface KeyMap { - // [key: string]: ReactNode; - // } + 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; // // React Components @@ -52,7 +53,7 @@ declare module React { // ---------------------------------------------------------------------- interface ComponentFactory

{ - (props?: P, ...children: any/*ReactNode*/[]): ReactElement

; + (props?: P, ...children: ReactNode[]): ReactElement

; } interface HTMLFactory extends ComponentFactory {} @@ -64,7 +65,7 @@ declare module React { interface TopLevelAPI { createClass

(spec: ComponentSpec): ComponentClass

; - createElement

(type: any/*ReactType*/, props: P, ...children: any/*ReactNode*/[]): ReactElement

; + createElement

(type: ComponentClass

| string, props: P, ...children: ReactNode[]): ReactElement

; createFactory

(componentClass: ComponentClass

): ComponentFactory

; render

(element: ReactElement

, container: Element, callback?: () => any): Component

; unmountComponentAtNode(container: Element): boolean; @@ -241,8 +242,8 @@ declare module React { // ---------------------------------------------------------------------- export interface ReactAttributes { - children?: any; // ReactNode - key?: any; // number | string + children?: ReactNode; + key?: number | string; ref?: string; // Event Attributes @@ -282,13 +283,13 @@ declare module React { onWheel?: WheelEventHandler; dangerouslySetInnerHTML?: { - __html: string + __html: string; }; } interface CSSProperties { columnCount?: number; - flex?: any; // number | string + flex?: number | string; flexGrow?: number; flexShrink?: number; fontWeight?: number; @@ -318,8 +319,8 @@ declare module React { autoComplete?: boolean; autoFocus?: boolean; autoPlay?: boolean; - cellPadding?: any; // number | string - cellSpacing?: any; // number | string + cellPadding?: number | string; + cellSpacing?: number | string; charSet?: string; checked?: boolean; classID?: string; @@ -342,8 +343,8 @@ declare module React { encType?: string; form?: string; formNoValidate?: boolean; - frameBorder?: any; // number | string - height?: any; // number | string + frameBorder?: number | string; + height?: number | string; hidden?: boolean; href?: string; hrefLang?: string; @@ -356,12 +357,12 @@ declare module React { list?: string; loop?: boolean; manifest?: string; - max?: any; // number | string + max?: number | string; maxLength?: number; media?: string; mediaGroup?: string; method?: string; - min?: any; // number | string + min?: number | string; multiple?: boolean; muted?: boolean; name?: string; @@ -394,7 +395,7 @@ declare module React { srcDoc?: string; srcSet?: string; start?: number; - step?: any; // number | string + step?: number | string; style?: CSSProperties; tabIndex?: number; target?: string; @@ -402,7 +403,7 @@ declare module React { type?: string; useMap?: string; value?: string; - width?: any; // number | string + width?: number | string; wmode?: string; // Non-standard Attributes @@ -415,49 +416,49 @@ declare module React { } interface SVGAttributes extends ReactAttributes { - cx?: any; // SVGLength | SVGAnimatedLength + cx?: SVGLength | SVGAnimatedLength; cy?: any; d?: string; - dx?: any; // SVGLength | SVGAnimatedLength - dy?: any; // SVGLength | SVGAnimatedLength + dx?: SVGLength | SVGAnimatedLength; + dy?: SVGLength | SVGAnimatedLength; fill?: any; // SVGPaint | string - fillOpacity?: any; // number | string + fillOpacity?: number | string; fontFamily?: string; - fontSize?: any; // number | string - fx?: any; // SVGLength | SVGAnimatedLength - fy?: any; // SVGLength | SVGAnimatedLength - gradientTransform?: any; // SVGTransformList | SVGAnimatedTransformList + fontSize?: number | string; + fx?: SVGLength | SVGAnimatedLength; + fy?: SVGLength | SVGAnimatedLength; + gradientTransform?: SVGTransformList | SVGAnimatedTransformList; gradientUnits?: string; markerEnd?: string; markerMid?: string; markerStart?: string; - offset?: any; // number | string - opacity?: any; // number | string + offset?: number | string; + opacity?: number | string; patternContentUnits?: string; patternUnits?: string; points?: string; preserveAspectRatio?: string; - r?: any; // SVGLength | SVGAnimatedLength - rx?: any; // SVGLength | SVGAnimatedLength - ry?: any; // SVGLength | SVGAnimatedLength + r?: SVGLength | SVGAnimatedLength; + rx?: SVGLength | SVGAnimatedLength; + ry?: SVGLength | SVGAnimatedLength; spreadMethod?: string; stopColor?: any; // SVGColor | string - stopOpacity?: any; // number | string + stopOpacity?: number | string; stroke?: any; // SVGPaint strokeDasharray?: string; strokeLinecap?: string; - strokeOpacity?: any; // number | string - strokeWidth?: any; // SVGLength | SVGAnimatedLength + strokeOpacity?: number | string; + strokeWidth?: SVGLength | SVGAnimatedLength; textAnchor?: string; - transform?: any; // SVGTransformList | SVGAnimatedTransformList + transform?: SVGTransformList | SVGAnimatedTransformList; version?: string; viewBox?: string; - x1?: any; // SVGLength | SVGAnimatedLength - x2?: any; // SVGLength | SVGAnimatedLength - x?: any; // SVGLength | SVGAnimatedLength - y1?: any; // SVGLength | SVGAnimatedLength - y2?: any; // SVGLength | SVGAnimatedLength - y?: any; // SVGLength | SVGAnimatedLength + x1?: SVGLength | SVGAnimatedLength; + x2?: SVGLength | SVGAnimatedLength; + x?: SVGLength | SVGAnimatedLength; + y1?: SVGLength | SVGAnimatedLength; + y2?: SVGLength | SVGAnimatedLength + y?: SVGLength | SVGAnimatedLength; } // @@ -637,13 +638,11 @@ declare module React { // React.Children // ---------------------------------------------------------------------- - // type Child = ReactElement | ReactText; - interface ReactChildren { - map(children: any/*ReactNode*/, fn: (child: any/*Child*/) => T): { [key:string]: T }; - forEach(children: any/*ReactNode*/, fn: (child: any/*Child*/) => any): void; - count(children: any/*ReactNode*/): number; - only(children: any/*ReactNode*/): any/*Child*/; + map(children: ReactNode, fn: (child: ReactChild) => T): { [key:string]: T }; + forEach(children: ReactNode, fn: (child: ReactChild) => any): void; + count(children: ReactNode): number; + only(children: ReactNode): ReactChild; } // @@ -659,7 +658,7 @@ declare module React { // ---------------------------------------------------------------------- interface TransitionGroupProps { - component?: any; // ReactType + component?: ReactType; childFactory?: (child: ReactElement) => ReactElement; } @@ -757,7 +756,7 @@ declare module React { mockComponent(mocked: MockedComponentClass, mockTagName?: string): ReactTestUtils; - isElementOfType(element: ReactElement, type: any/*ReactType*/): boolean; + isElementOfType(element: ReactElement, type: ReactType): boolean; isDOMComponent(instance: Component): boolean; isCompositeComponent(instance: Component): boolean; isCompositeComponentWithType(instance: Component, type: ComponentClass): boolean;