【问题标题】:TypeScript 1.6 error: JSX element type XXX does not have any construct or call signatureTypeScript 1.6 错误:JSX 元素类型 XXX 没有任何构造或调用签名
【发布时间】:2015-09-21 12:03:46
【问题描述】:
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) 一起使用

【问题讨论】:

  • 奇怪。使用 1.6.2 从命令行编译时对我来说效果很好。
  • Typescript 安装非常糟糕。我的环境路径中有 Typescript/Typescript/1.2/Typescript/1.3/Typescript/1.4。当您认为自己是 1.6 时,您可能没有引用。

标签: visual-studio-2013 typescript typescript1.6


【解决方案1】:

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

建议:

  • 确保 Visual Studio 真正使用 typescript 1.6
  • 确保您已包含react.d.ts,并尽量不要使用全球版本
  • 确保您有可用的React 变量(例如import React = require('react');)。

【讨论】:

  • 我想通了...我通过 NuGet "React.TypeScript.DefinitelyTyped (V 0.1.12) 加载了 react.d.ts 文件...我用这个版本更新了它:@987654322 @
猜你喜欢
  • 2016-03-05
  • 2021-07-10
  • 2018-02-15
  • 2021-11-30
  • 2016-10-07
  • 2019-06-06
  • 2021-09-21
  • 2021-12-26
  • 2017-12-05
相关资源
最近更新 更多