diff --git a/tests/baselines/reference/tsxUnionTypeComponent.errors.txt b/tests/baselines/reference/tsxUnionTypeComponent.errors.txt new file mode 100644 index 00000000000..6650db4533b --- /dev/null +++ b/tests/baselines/reference/tsxUnionTypeComponent.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/jsx/file.tsx(28,2): error TS2604: JSX element type 'X' does not have any construct or call signatures. + + +==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== + + import React = require('react'); + + interface ComponentProps { + AnyComponent: React.StatelessComponent | React.ComponentClass; + } + + class MyComponent extends React.Component { + render() { + const { AnyComponent } = this.props; + const someProps = {}; + const button = + return (
{button}
); + } + } + + }/> + + class MyButtonComponent extends React.Component<{},{}> { + } + + + + type Invalid = string | React.ComponentClass; + + var X: Invalid = ""; + + // Should fail + ~ +!!! error TS2604: JSX element type 'X' does not have any construct or call signatures. + \ No newline at end of file diff --git a/tests/baselines/reference/tsxUnionTypeComponent.js b/tests/baselines/reference/tsxUnionTypeComponent.js new file mode 100644 index 00000000000..5b105abcb83 --- /dev/null +++ b/tests/baselines/reference/tsxUnionTypeComponent.js @@ -0,0 +1,71 @@ +//// [file.tsx] + +import React = require('react'); + +interface ComponentProps { + AnyComponent: React.StatelessComponent | React.ComponentClass; +} + +class MyComponent extends React.Component { + render() { + const { AnyComponent } = this.props; + const someProps = {}; + const button = + return (
{button}
); + } +} + + }/> + +class MyButtonComponent extends React.Component<{},{}> { +} + + + +type Invalid = string | React.ComponentClass; + +var X: Invalid = ""; + + // Should fail + + +//// [file.js] +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +var React = require('react'); +var MyComponent = (function (_super) { + __extends(MyComponent, _super); + function MyComponent() { + _super.apply(this, arguments); + } + MyComponent.prototype.render = function () { + var AnyComponent = this.props.AnyComponent; + var someProps = {}; + var button = React.createElement(AnyComponent, __assign({}, someProps)); + return (React.createElement("div", null, button)); + }; + return MyComponent; +}(React.Component)); +React.createElement(MyComponent, {AnyComponent: function () { return React.createElement("button", null, "test"); }}); +var MyButtonComponent = (function (_super) { + __extends(MyButtonComponent, _super); + function MyButtonComponent() { + _super.apply(this, arguments); + } + return MyButtonComponent; +}(React.Component)); +React.createElement(MyComponent, {AnyComponent: MyButtonComponent}); +var X = ""; +React.createElement(X, null); // Should fail diff --git a/tests/cases/conformance/jsx/tsxUnionTypeComponent.tsx b/tests/cases/conformance/jsx/tsxUnionTypeComponent.tsx new file mode 100644 index 00000000000..073d4f37200 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxUnionTypeComponent.tsx @@ -0,0 +1,32 @@ +// @filename: file.tsx +// @jsx: react +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react'); + +interface ComponentProps { + AnyComponent: React.StatelessComponent | React.ComponentClass; +} + +class MyComponent extends React.Component { + render() { + const { AnyComponent } = this.props; + const someProps = {}; + const button = + return (
{button}
); + } +} + + }/> + +class MyButtonComponent extends React.Component<{},{}> { +} + + + +type Invalid = string | React.ComponentClass; + +var X: Invalid = ""; + + // Should fail