typescript - JSX 元素类型 'XXX' 没有任何构造或调用签名

标签 typescript jsx

我想在 typescript 中使用 material-ui。

/// <reference path="../../../typings/react/react.d.ts"/>
import React = __React;
import * as FlatButton from "material-ui/lib/flat-button";

interface ATCProps{
    clickHandler:__React.MouseEventHandler;
}

export default class AddToCartBtn extends React.Component<ATCProps,any>{
    render(){
        return (
            <FlatButton></FlatButton>  // -> error
        )
    }
}

平面按钮.d.ts

declare module "material-ui/lib/flat-button" {
    import ReactElement = __React.ReactElement;
    import Component = __React.Component;
    interface FlatButton extends __React.Component<any,any>{
    }
    export default FlatButton;
}

错误:(15, 14) TS2604:JSX 元素类型“FlatButton”没有任何构造或调用签名。

最佳答案

您需要将 interface FlatButton 替换为 class FlatButton。您导出的模块定义没有任何关联值。

关于typescript - JSX 元素类型 'XXX' 没有任何构造或调用签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34025236/

相关文章:

sql-server - 元素隐式具有 'any' 类型,因为类型 'string' 的表达式不能用于索引类型 'Type'

javascript - Object.keys 但不按顺序 JS/TS

javascript - JSX: map 内的条件语句

javascript - 我应该如何重构这段代码以防止函数在定义之前被使用

reactjs - ionic react : How to properly type (typescript) event object parameter in delegated anonymous onIonChange event handler

javascript - 我如何在 typescript 中使用 firefox require 函数

typescript 不推断表达式签名匹配

html - Flexbox - 如何防止扩展超出它的容器

javascript - 如何在 ReactJS JSX 中执行嵌套的 if else 语句?

reactjs - 模块解析失败: es6 react component with JSX inside . JS文件