Skip to content

Parser treats comma expression as type arguments #46604

Closed
@mheiber

Description

@mheiber

Bug Report

The last line below evaluates to true but is rejected by TS due to < b, c > being parsed as a type parameter list:

const a = 1;
const b = 2;
const c = 3;
const d = 4;
   (a < b, c > (d));  // Error: c refers to a value, but is being used as a type here

Adapted from rust-lang/rfcs#2527 (comment).

Sorry if this issue was known already.

🔎 Search Terms

turbofish
ambiguity
generics
"refers to a value"

🕗 Version & Regression Information

3.5.1 through 4.5.0-beta

This is the behavior in every version I tried, and I reviewed the FAQ for entries about parsing and generics.
3.33 has a slightly different error message.

Note: when using // @ts-check on a JS file the only error is that the left side of the comma expression is unused (good).

⏯ Playground Link

playground

ts-ast-viewer

💻 Code

const a = 1;
const b = 2;
const c = 3;
const d = 4;
   (a < b, c > (d)); 
//  |   |  ^ Error: e refers to a value, but is being used as a type here
//  |   ^ Error: c refers to a value, but is being used as a type here
//  ^ Error: This expression is not callable

🙁 Actual behavior

  • Errors:

    • Error: This expression is not callable
    • Error: c refers to a value, but is being used as a type here
    • e refers to a value, but is being used as a type here
  • And the AST contains CallExpression

🙂 Expected behavior

  • No errors
  • The AST contains BinaryExpression with LessThanToken etc. instead of CallExpression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions