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

babel-types typescript generator emits wrong type for #11100

anilanar opened this issue Feb 6, 2020 · 1 comment

babel-types typescript generator emits wrong type for #11100

anilanar opened this issue Feb 6, 2020 · 1 comment


Copy link

@anilanar anilanar commented Feb 6, 2020

TLDR; type generator script falls short when generating a type for thus it falls back to any.

Proposed change:

  1. Define a helper function called refine. I took the name refine from Refinement types:
export function refine(fn: Validator): Validator {
  function validate(...args) {
  validate.refinementOf = fn;
  1. Use refine for field validator definition:
    validate: refine(valueOfType('string'), function(node, key, val) {
        if (!process.env.BABEL_TYPES_8_BREAKING) return;

        if (!esutils.keyword.isIdentifierNameES6(val)) {
          throw new TypeError(`"${val}" is not a valid identifier name`);
  1. Update stringifyValidator:
if (validator.refinementOf) {
  return stringifyValidator(validator.refinementOf, nodePrefix);
  1. (Optional) Fix chainOf handling in stringifyValidator. It assumes the length of chain is 2 and takes the type info from the second validator. It should take it from the last validator in the chain. After this change, it'd be helpful to take a look at diff of generated types before/after the fix.

  2. (Semi-joke) Replace Flow with Typescript.


This comment has been minimized.

Copy link

@babel-bot babel-bot commented Feb 6, 2020

Hey @anilanar! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.