Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Support new flowtype syntax for exact object types #121

Closed
Riim opened this issue Sep 23, 2016 · 8 comments
Closed

Support new flowtype syntax for exact object types #121

Riim opened this issue Sep 23, 2016 · 8 comments

Comments

@Riim
Copy link

Riim commented Sep 23, 2016

flow v0.32.0:

New syntax for exact object types: use {| and |} instead of { and }. Where {x: string} contains at least the property x, {| x: string |} contains ONLY the property x.

@gcanti
Copy link
Owner

gcanti commented Sep 23, 2016

Is this new syntax already supported by babel? In the meanwhile support for the $Exact magic type might be added

@Riim
Copy link
Author

Riim commented Sep 23, 2016

Probably soon will support: babel/babel#3702

gcanti added a commit that referenced this issue Sep 25, 2016
@gcanti gcanti closed this as completed in 673bef0 Sep 25, 2016
@gcanti
Copy link
Owner

gcanti commented Sep 25, 2016

Support for $Exact magic type released in https://github.com/gcanti/babel-plugin-tcomb/releases/tag/v0.3.14

@gcanti
Copy link
Owner

gcanti commented Sep 30, 2016

@Riim added support for exact object syntax https://github.com/gcanti/babel-plugin-tcomb/releases/tag/v0.3.15

@Riim
Copy link
Author

Riim commented Sep 30, 2016

Thanks! With syntax is now all is well. Now would be appropriate test for it.

https://yadi.sk/i/jZFp95HbvvtDs

The generated tests have not changed:

'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.default = convertLocationData;

var _tcomb = __webpack_require__(1);

var _tcomb2 = _interopRequireDefault(_tcomb);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// @flow

function convertLocationData(locationData /*: {|
                                            k: string,
                                            v: string
                                          |}*/) {
    _assert(locationData, _tcomb2.default.interface({
        k: _tcomb2.default.String,
        v: _tcomb2.default.String
    }), 'locationData');

    return {
        id: locationData.v,
        name: locationData.k
    };
}

console.log(convertLocationData({ k: '1', v: '2', qqq: '3' }));

function _assert(x, type, name) {
    function message() {
        return 'Invalid value ' + _tcomb2.default.stringify(x) + ' supplied to ' + name + ' (expected a ' + _tcomb2.default.getTypeName(type) + ')';
    }

    if (_tcomb2.default.isType(type)) {
        if (!type.is(x)) {
            type(x, [name + ': ' + _tcomb2.default.getTypeName(type)]);

            _tcomb2.default.fail(message());
        }

        return type(x);
    }

    if (!(x instanceof type)) {
        _tcomb2.default.fail(message());
    }

    return x;
}
    "babel-core": "^6.16.0",
    "babel-plugin-tcomb": "^0.3.15",
  },
  "dependencies": {
    "tcomb": "^3.2.15",

@gcanti
Copy link
Owner

gcanti commented Sep 30, 2016

Ouch! Thanks for the report

@gcanti
Copy link
Owner

gcanti commented Sep 30, 2016

Sorry for the inconvenience, should be fixed in the new release

@Riim
Copy link
Author

Riim commented Oct 8, 2016

Many thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants