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

not check typed array on return value #78

Closed Riim closed 8 years ago

Riim commented 8 years ago

Input:

function findBlocks(el: HTMLElement): Array<HTMLElement> {
    let blocks = [];

    if (el.hasAttribute('rt-is') || getComponentSubclass(el.tagName.toLowerCase())) {
        blocks.push(el);
    }

    blocks.push.apply(blocks, el.querySelectorAll(getComponentSelector()));

    return blocks;
}

Output:

function findBlocks(el) {
    if (!(el instanceof HTMLElement)) {
        throw new TypeError('Value of argument "el" violates contract, expected HTMLElement got ' + (el === null ? 'null' : (typeof el === 'undefined' ? 'undefined' : _typeof(el)) === 'object' && el.constructor ? el.constructor.name || '[Unknown Object]' : typeof el === 'undefined' ? 'undefined' : _typeof(el)));
    }

    function _ref(_id) {
        if (!(Array.isArray(_id) && _id.every(function (item) {
            return item instanceof HTMLElement;
        }))) {
            throw new TypeError('Function "findBlocks" return value violates contract, expected Array<HTMLElement> got ' + (_id === null ? 'null' : (typeof _id === 'undefined' ? 'undefined' : _typeof(_id)) === 'object' && _id.constructor ? _id.constructor.name || '[Unknown Object]' : typeof _id === 'undefined' ? 'undefined' : _typeof(_id)));
        }

        return _id;
    }

    var blocks = [];

    if (el.hasAttribute('rt-is') || getComponentSubclass(el.tagName.toLowerCase())) {
        blocks.push(el);
    }

    blocks.push.apply(blocks, el.querySelectorAll(getComponentSelector()));

    return blocks;
}

_ref is defined and not used.