From 8d353f8b4793f3748e7938a295cfaca43314ab84 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Sun, 15 Mar 2015 14:42:40 +0000 Subject: [PATCH] Update to React v0.13 typings * The main React typings for v0.13 declare an external module rather than one which declares the internal module React in the global namespace. * Adjust the ' { */ register(Task.copy, [Task.scripts], () => { return gulp.src(path.join(dirs.build, dirs.src, match(set(".d.ts", ".js")))) - .pipe(replace("/// ", "")) + .pipe(replace(" { sortOutput: false, target: "ES5" })); + drain(compiler.js); drain(compiler.dts); function drain(stream: NodeJS.ReadWriteStream): void { diff --git a/src/component.ts b/src/component.ts index 8fe4145..a887490 100644 --- a/src/component.ts +++ b/src/component.ts @@ -1,8 +1,10 @@ /// + import Mixin = require("././mixin"); +import react = require("react"); -class Component extends Mixin implements React.CompositeComponent { - render(): React.ReactElement { +class Component extends Mixin implements react.ClassicComponent { + render(): react.ReactElement { return null; } } diff --git a/src/create_class.ts b/src/create_class.ts index db29f85..79de533 100644 --- a/src/create_class.ts +++ b/src/create_class.ts @@ -3,8 +3,8 @@ import extractPrototype = require("./extract_prototype"); import Component = require("./component"); import react = require("react"); -function createClass(clazz: { new(): Component }, mixins?: React.Mixin[]): React.ComponentClass

{ - var spec: React.ComponentSpec = extractPrototype(clazz); +function createClass(clazz: { new(): Component }, mixins?: react.Mixin[]): react.ComponentClass

{ + var spec: react.ComponentSpec = extractPrototype(clazz); spec.displayName = clazz.prototype.constructor.name; if (spec.componentWillMount !== undefined) { var componentWillMount = spec.componentWillMount; diff --git a/src/create_mixin.ts b/src/create_mixin.ts index 47cff23..20591d6 100644 --- a/src/create_mixin.ts +++ b/src/create_mixin.ts @@ -1,8 +1,9 @@ /// import extractPrototype = require("./extract_prototype"); import Mixin = require("./mixin"); +import react = require("react"); -function createMixin(clazz: { new(): Mixin }): React.Mixin { +function createMixin(clazz: { new(): Mixin }): react.Mixin { return extractPrototype(clazz); } diff --git a/src/mixin.ts b/src/mixin.ts index 996b4ae..d4762e5 100644 --- a/src/mixin.ts +++ b/src/mixin.ts @@ -1,18 +1,20 @@ /// import NotImplementedError = require("./not_implemented_error"); +import react = require("react"); -class Mixin implements React.Mixin { +class Mixin implements react.Mixin { public refs: { - [key: string]: React.Component + [key: string]: react.Component }; public props: P; public state: S; + public context: any; getDOMNode(): Element { throw new NotImplementedError("getDomNode"); } - setState(nextState: S, callback?: () => void): void { + setState(nextState: S | ((prevState: S, props: P) => S), callback?: () => void): void { throw new NotImplementedError("setState"); } diff --git a/test/create_class_spec.ts b/test/create_class_spec.ts index 4f4a1c7..19fac4a 100644 --- a/test/create_class_spec.ts +++ b/test/create_class_spec.ts @@ -1,4 +1,6 @@ /// +/// + import chai = require("chai"); import React = require("react"); import TypedReact = require("../src/index"); @@ -37,13 +39,13 @@ class LifeCycleMixin extends TypedReact.Mixin { } class HelperMixin extends TypedReact.Mixin { - greet(greeting: string): React.ReactHTMLElement { + greet(greeting: string): React.HTMLElement { return React.DOM.h1(null, greeting, this.props.name); } } class MixinTest extends FactoryTest implements HelperMixin { - greet: (greeting: string) => React.ReactHTMLElement; + greet: (greeting: string) => React.HTMLElement; render() { return this.greet(this.greeting); @@ -52,7 +54,7 @@ class MixinTest extends FactoryTest implements HelperMixin { describe("createFactory", () => { var clazz: React.ComponentClass; - var factory: React.ComponentFactory; + var factory: React.Factory; var element: React.ReactElement; var name = "test"; diff --git a/tsd.json b/tsd.json index 55870cc..ae04564 100644 --- a/tsd.json +++ b/tsd.json @@ -51,7 +51,7 @@ "commit": "b5131a650f037aa1d962b9ff63a1bb929dc2dcf7" }, "react/react.d.ts": { - "commit": "b5131a650f037aa1d962b9ff63a1bb929dc2dcf7" + "commit": "57340eca1e3aac68d59cc981b441da834ca38235" }, "vinyl/vinyl.d.ts": { "commit": "b5131a650f037aa1d962b9ff63a1bb929dc2dcf7"