Skip to content

@babel/types TypeScript declaration file has some errors above v7.8.0 #10998

@xuyuanxiang

Description

@xuyuanxiang

Bug Report

When I upgrade @babel/types to 7.8.0, the following TypeScript source files had some compilation errors:

import {
  arrowFunctionExpression,
  identifier,
  blockStatement,
  returnStatement,
  program,
  variableDeclaration,
  variableDeclarator,
  stringLiteral,
} from '@babel/types';

// error TS2554: Expected 4-7 arguments, but got 2.
arrowFunctionExpression(
  [identifier('arg')],
  blockStatement([returnStatement(identifier('arg'))]),
);

//  error TS2554: Expected 5 arguments, but got 1.
program([
  variableDeclaration('const', [
    variableDeclarator(identifier('foo'), stringLiteral('bar')),
  ]),
]);

I followed the error message and fixed it like this:

arrowFunctionExpression(
  [identifier('arg')],
  blockStatement([returnStatement(identifier('arg'))]),
  false,
  false,
);

program(
  [
    variableDeclaration('const', [
      variableDeclarator(identifier('foo'), stringLiteral('bar')),
    ]),
  ],
  undefined,
  undefined,
  undefined,
  '',
);

Typescript compilation was successful,But when I use node to execute the compiled JS file,@babel/types threw errors:

Error: ArrowFunctionExpression: Too many arguments passed. Received 4 but can receive no more than 3

Error: Program: Too many arguments passed. Received 5 but can receive no more than 4

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true
  },
}

Environment

  System:
    OS: macOS Mojave 10.14.6
  Binaries:
    Node: 12.14.0 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  npmPackages:
    @babel/types: ^7.8.0 => 7.8.0 

Metadata

Metadata

Assignees

Labels

Has PRi: regressionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: types

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions