Skip to content

any in ClassDeclaration fields in TypeScript type in @babel/types since 7.8.0 #11474

@grubersjoe

Description

@grubersjoe

Bug Report

  • I would like to work on a fix!

Current Behavior

I updated @babel/types from ~7.7.0 to the latest version 7.9.5 and noticed that all of a sudden I get new TypeScript errors. The Problem is that beginning with @babel/types@7.8.0 a lot of fields of the ClassDeclaration type use any instead of more specific types used before (compare below). Because I use the noImplicitAny option of the TypeScript compiler new errors occur.

// Current type declaration (^7.8.0)
export interface ClassDeclaration extends BaseNode {
  type: "ClassDeclaration";
  id: any;
  superClass: any;
  body: any;
  decorators: any;
  abstract: boolean | null;
  declare: boolean | null;
  implements: any;
  mixins: any;
  superTypeParameters: any;
  typeParameters: any;
}

Expected behavior/code

I would expect that an minor upgrade does not break types. I'm not sure if there was a specific reason to set this to any or if it is simply a bug in type generation or somewhere else.

// Old type declaration (~7.7.0)
export interface ClassDeclaration extends BaseNode {
  type: "ClassDeclaration";
  id: Identifier | null;
  superClass: Expression | null;
  body: ClassBody;
  decorators: Array<Decorator> | null;
  abstract: boolean | null;
  declare: boolean | null;
  implements: Array<TSExpressionWithTypeArguments | ClassImplements> | null;
  mixins: any | null;
  superTypeParameters: TypeParameterInstantiation | TSTypeParameterInstantiation | null;
  typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop | null;
}

Environment

System:
    OS: Linux 5.6 Arch Linux
Binaries:
    Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
    Yarn: 1.22.4 - /usr/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
 npmPackages:
    @babel/types: ~7.8.0 => 7.8.7 
Monorepo: no
How you are using Babel: babel-loader

Possible Solution

Use the more specific types as before.

Should I provide more information/context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions