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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse error on function parameter type signature within member signature in interface #236

Closed
patrickt opened this issue Feb 14, 2023 · 1 comment · Fixed by #273
Closed
Labels

Comments

@patrickt
Copy link
Contributor

The following piece of code is valid but it is parsed incorrectly:

export interface EntityOptions {
    orderBy: ((object: any) => String);
}

Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript:
https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgURQRgE8B5MGBCJAZzgG8AoOVuaAEzQCESAuOAGUYUZAHM4AHzgAKGRABGAK2DYYAzEhIBKOAF4AfEJHipcTToDcTAL5A

The output of tree-sitter parse is the following:

(program [0, 0] - [3, 0]
  (export_statement [0, 0] - [2, 1]
    declaration: (interface_declaration [0, 7] - [2, 1]
      name: (type_identifier [0, 17] - [0, 30])
      body: (object_type [0, 31] - [2, 1]
        (property_signature [1, 4] - [1, 38]
          name: (property_identifier [1, 4] - [1, 11])
          type: (type_annotation [1, 11] - [1, 38]
            (parenthesized_type [1, 13] - [1, 38]
              (parenthesized_type [1, 14] - [1, 27]
                (predefined_type [1, 15] - [1, 21])
                (ERROR [1, 21] - [1, 26]))
              (ERROR [1, 28] - [1, 37]
                (identifier [1, 31] - [1, 37])))))))))
/tmp/go.ts      0 ms    (ERROR [1, 21] - [1, 26])

Removing the object: any type annotation fixes it.

@patrickt patrickt added the bug label Feb 14, 2023
@casr
Copy link

casr commented Apr 9, 2023

Looks like the parser is recognising the object part as predefined_type before matching it as a required_parameter. If you rename object to something else like obj it will start to work.

Looking at the TypeScript parser, it seems it is okay with using object as a parameter name.

(btw, you probably don't want to use things like String as a type in this context)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants