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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Process correct ts file throw error: expected node to be of a type ["FlowType"] but instead got "TSTypeReference" #16232

Closed
1 task
huanguolin opened this issue Jan 24, 2024 · 5 comments
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@huanguolin
Copy link

huanguolin commented Jan 24, 2024

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

The code is simplified from the 'asyncThrottle.ts' file.

export function action<TArgs extends readonly unknown[]>(
    func: (...args: TArgs) => void,
) {
    let currentArgs: TArgs | null = null;

    const execFunc = () => {
        if (currentArgs) {
            const args = currentArgs;
            func(...args);
        }
    };

    return (...args: TArgs) => {
        currentArgs = args;
        // do something
    };
}

Configuration file name

babel.config.json

Configuration

{
    "presets": ["@babel/preset-env", "@babel/preset-typescript"]
}

Current and expected behavior

Expected behavior: no error.
Current behavior: throw error:

TypeError: /Users/alvin/codeWork/babel-ts-transform-error/src/test.ts: Property types[0] of UnionTypeAnnotation expected node to be of a type ["FlowType"] but instead got "TSTypeReference"
    at validate (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/types/lib/definitions/utils.js:106:11)
    at validator (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/types/lib/definitions/utils.js:81:7)
    at Object.validate (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/types/lib/definitions/utils.js:183:7)
    at validateField (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/types/lib/validators/validate.js:21:9)
    at validate (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/types/lib/validators/validate.js:15:3)
    at validateNode (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/types/lib/builders/validateNode.js:12:27)
    at unionTypeAnnotation (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/types/lib/builders/generated/index.js:1249:36)
    at createFlowUnionType (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/types/lib/builders/flow/createFlowUnionType.js:14:43)
    at createUnionType (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/traverse/lib/path/inference/util.js:19:16)
    at getTypeAnnotationBindingConstantViolations (/Users/alvin/codeWork/babel-ts-transform-error/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js:50:36) {
  code: 'BABEL_TRANSFORM_ERROR'
}

Environment

node: v16.17.0
package.json:

{
  "scripts": {
    "build": "babel src/test.ts --out-file output/test.js"
  },
  "devDependencies": {
    "@babel/cli": "^7.23.4",
    "@babel/core": "^7.23.7",
    "@babel/preset-env": "^7.23.8",
    "@babel/preset-typescript": "^7.23.3",
    "typescript": "^5.3.3"
  }
}

Possible solution

No response

Additional context

I probably debugged it, and that's where the problems should have started, and since I'm relatively new to babel internals, I didn't continue.
debug.png

@babel-bot
Copy link
Collaborator

Hey @huanguolin! 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.

@huanguolin huanguolin changed the title [Bug]: Process correct ts file throw error: Property types[0] of UnionTypeAnnotation expected node to be of a type ["FlowType"] but instead got "TSTypeReference" [Bug]: Process correct ts file throw error: expected node to be of a type ["FlowType"] but instead got "TSTypeReference" Jan 24, 2024
@huanguolin
Copy link
Author

@liuxingbaoyu
Copy link
Member

This should be fixed by #15383 and we should have a patch released soon.

@nicolo-ribaudo
Copy link
Member

I can release now

@nicolo-ribaudo
Copy link
Member

https://github.com/babel/babel/releases/tag/v7.23.9

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Apr 26, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants