Skip to content

parser: BindingIdentifier typeAnnotation is typed as null in generated types.d.ts #22134

Description

@camc314

The generated parser TypeScript types currently declare BindingIdentifier.typeAnnotation as always null, but the parser can emit a real TSTypeAnnotation for binding identifiers.

Reference discussion: https://discord.com/channels/1079625926024900739/1080712024683708466/1500159726980432084

AI disclosure: this issue text was drafted with AI assistance and reviewed before filing.

Reproduction

Parse a TypeScript binding identifier with a type annotation, for example:

const x: string = "foo";

The parsed AST includes a BindingIdentifier whose typeAnnotation is populated:

{
  type: "Identifier",
  name: "x",
  typeAnnotation: {
    type: "TSTypeAnnotation",
    typeAnnotation: {
      type: "TSStringKeyword"
    }
  }
}

Current Type Definition

In types.d.ts, BindingIdentifier is currently generated as:

export interface BindingIdentifier extends Span {
  type: "Identifier";
  decorators?: [];
  name: string;
  optional?: false;
  typeAnnotation?: null;
  parent?: Node;
}

Expected

IdentifierReference.typeAnnotation should remain null, because annotations are not valid on identifier references:

const y = x: string; // invalid

But BindingIdentifier.typeAnnotation should allow a real TypeScript annotation, because bindings can be annotated:

const x: string = "foo";

Expected type:

export interface BindingIdentifier extends Span {
  type: "Identifier";
  decorators?: [];
  name: string;
  optional?: false;
  typeAnnotation?: TSTypeAnnotation | null;
  parent?: Node;
}

Notes

This appears to be a generated type mismatch rather than a parser AST output issue. The generated files point to:

tasks/ast_tools/src/generators/typescript.rs

as the source for types.d.ts generation.

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions