0
var CommentList = React.createClass({
          render: function () {
        return (
            <div className="commentList">
                Hello, world!I am a CommentList.
                </div>
        );
          }
});

var CommentBox = React.createClass({
          render: function () {
        return (
            <div className="commentBox">
                <h1>Comments</h1>
                <CommentList /> //ERROR
                </div>
        );
    }
});

React.render(
          React.createElement(CommentBox, null),
          document.getElementById('content')
);

使用此代码,我收到以下错误消息: JSX 元素类型“CommentList”没有任何构造或调用签名。

相同的代码适用于纯 HTML/JS(遵循本教程:https ://facebook.github.io/react/docs/tutorial.html )

我不知道为什么 TypeScript 不喜欢它。将 Visual Studio 2013 与 TS 1.6 一起使用(http://blogs.msdn.com/b/typescript/archive/2015/09/16/announcing-typescript-1-6.aspx

4

1 回答 1

2

它工作正常,没有错误(来自 atom-typescript 的屏幕截图):

在此处输入图像描述

建议:

  • 确保 Visual Studio 真正使用 typescript 1.6
  • 确保已react.d.ts包含并尽量不要使用全局版本
  • 确保您有React可用的变量(例如import React = require('react');)。
于 2015-09-21T23:26:07.120 回答