Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate assertion for Object Type Application? #16

Closed
victor-homyakov opened this issue Jan 16, 2017 · 1 comment · Fixed by #17
Closed

Generate assertion for Object Type Application? #16

victor-homyakov opened this issue Jan 16, 2017 · 1 comment · Fixed by #17

Comments

@victor-homyakov
Copy link
Contributor

https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#type-application describes possible Type Application for Object: Object<string, someType>. It's easy to implement assert generation for this case as

/**
 * @param {Object<string, number>} x
 */

=>

Object.values(x).every(function (item) {
    return typeof item  === 'number';
});

AFAIK there is no need to generate assertion for first type (for object keys), as it will always be string.

If it looks good, then I'll make a PR.

@azu
Copy link
Owner

azu commented Jan 16, 2017

It looks good to me.

But, Object.values() is not parts of current ECMAScript yet.
(It will be included in ECMAScript 2017. Some enviroment is not implemented yet.)

It is better that use Object.keys(x) instead of Object.values(x), I think.

Object.keys(x).every(function (key) {
    return typeof x[key]  === 'number';
});

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

Successfully merging a pull request may close this issue.

2 participants