codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

typecheck tries to wrap PropTypes.shape #109

Closed mmakarin closed 8 years ago

mmakarin commented 8 years ago

Source:

import React, { PropTypes } from "react";

export default class Table extends PureComponent {
    static propTypes = {
        columns: PropTypes.arrayOf(PropTypes.shape({
            title: PropTypes.string,
            render: PropTypes.func
        })),
        data: PropTypes.array
    };

    ...

Output

var Table = _wrapComponent("Table")((_temp = _class = function (_PureComponent) {
    _inherits(Table, _PureComponent);

    function Table() {
        _classCallCheck(this, Table);

        return _possibleConstructorReturn(this, Object.getPrototypeOf(Table).apply(this, arguments));
    }

    _createClass(Table, [{
        key: "render",
        value: function render() {
             ...
        }
    }]);

    return Table;
}(_reactPureRender.PureComponent), _class.propTypes = {
    columns: _react2.PropTypes.arrayOf(_wrapComponent("_component")(_react2.PropTypes.shape({
        title: _react2.PropTypes.string,
        render: _react2.PropTypes.func
    }))),
    data: _react2.PropTypes.array
}, _temp));

And it fails on the line

var originalRender = ReactClass.prototype.render;

with the following error because PropTypes.Shape.prototype.render is undefined

Uncaught TypeError: Cannot read property 'render' of undefined
wrapToCatchErrors @ index.js:30(anonymous function)
@ Table.js:65(anonymous function)
@ Table.js:151(anonymous function) 
...
phpnode commented 8 years ago

@mmakarin this doesn't look like any of the typecheck transforms, can you post the output when typecheck is disabled?

mmakarin commented 8 years ago

Oops. Excuse me. It's react-transform-catch-errors fault.