benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API
MIT License
1.13k stars 195 forks source link

TSTypeOperatorBuilder interface call signature should accept a typeAnnotation parameter #947

Open lachlanhunt opened 9 months ago

lachlanhunt commented 9 months ago

The current TSTypeOperatorBuilder interface:

export interface TSTypeOperatorBuilder {
  (operator: string): namedTypes.TSTypeOperator;
  from(
    params: {
      comments?: K.CommentKind[] | null;
      loc?: K.SourceLocationKind | null;
      operator: string;
      typeAnnotation: K.TSTypeKind;
    }
  ): namedTypes.TSTypeOperator;
}

Since the typeAnnotation is required, attempting to create a TSTypeOperator by calling the function isn't possible. It can only be done by using the .from() method instead.

The call signature should have a second parameter for the typeAnnotation

export interface TSTypeOperatorBuilder {
  (operator: string, typeAnnotation: K.TSTypeKind): namedTypes.TSTypeOperator;
  ...
}

Some code to reproduce the error can be viewed here.

https://astexplorer.net/#/gist/2328ddf6e049e141a5db2293d6d67668/27d29233f044354b19d639701ceff667448b4b55