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

Add a way to annotate a callback #119

Closed gajus closed 7 years ago

gajus commented 8 years ago

Example:

import cheerio from 'cheerio';

type CallbackType = (element: cheerio, index: ?number): any => {};

export default (selector: cheerio, callback: CallbackType): Array<string> => {
    const values = [];

    selector.each((index, element) => {
        values.push(callback(element, index));
    });

    return values;
};
phpnode commented 8 years ago

The annotation should work as in it verifies it is a function but it seems impossible to verify args and return type in a non intrusive way. Maybe wrapping in another fn would be OK but there's definite edge cases where it would do the wrong thing.

phpnode commented 7 years ago

works in flow-runtime