5
votes

I want to use material-ui in typescript.

/// <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
        )
    }
}

flat-button.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;
}

Error:(15, 14) TS2604: JSX element type 'FlatButton' does not have any construct or call signatures.

2

2 Answers

3
votes

You need to replace interface FlatButton with class FlatButton. The module definition you've exported doesn't have any value associated with it.

0
votes

First: please try this.

import FlatButton from "material-ui/lib/flat-button";

Second: why this?

It is default exports.

// fileA: export default module
declare let $: JQuery;
export default $;
// fileB: import module from default module
import $ from "jquery";

if material-ui/lib/flat-button is 'default exports',we should use a different import form.

Third: what happend when import * as FlatButton from "XXX"

import * as FlatButton from "XXX" means import the entire module into a single variable.

// the outcome is an object with a default property
{
  default: FlatButton(props)
}

more in modules: default exports.