gcanti / babel-plugin-tcomb

Babel plugin for static and runtime type checking using Flow and tcomb
MIT License
482 stars 22 forks source link

Class property function destructuring does not correctly validate #146

Closed NervosaX closed 8 years ago

NervosaX commented 8 years ago

I have the following code:

type PresenterObject = {
    body: string[],
    article: string[]
}

export default class Layout extends React.Component {
    handleDeckClassChanged = ({ body, article }: PresenterObject): void => {
        this.props.signals.slides.bodyModeChanged({ body, article });
    }

        ...
}

This uses class properties to bind the function to scope. It seems that when generating the tcomb assertion it generates:

_this.handleDeckClassChanged = function (_ref2) {
    var body = _ref2.body;
    var article = _ref2.article;

    _assert(_arguments[0], PresenterObject, "{ body, article }");

    var ret = function (_ref3) {
      var body = _ref3.body;
      var article = _ref3.article;

      _this.props.signals.slides.bodyModeChanged({ body: body, article: article });
    }.call(_this2, {
      body: body,
      article: article
    });

    _assert(ret, _t.Nil, "return value");

    return ret;
  }, _temp), _possibleConstructorReturn(_this, _ret);
}

Where _assert(_arguments[0], PresenterObject, "{ body, article }"); is using arguments from outside of the function rather than directly using _ref2 or even just arguments[0]

This means my assertion always fails.

gcanti commented 8 years ago

Could you please try with the last release? https://github.com/gcanti/babel-plugin-tcomb/releases/tag/v0.3.22

NervosaX commented 8 years ago

Ah yes, it does seem to be resolved in the latest version. Sorry about that.