microsoft / microsoft/TypeScript

Parser misinterprets async() calls in conditional expressions as async arrow functions

Open
#64,231 3 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
Go
Stars
111k
Forks
14.3k
PR merge metrics
PR metrics pending

Description

### 🔎 Search Terms

parser, async, conditional

### 🕗 Version & Regression Information

- This is the behavior in every version I tried

### ⏯ Playground Link

_No response_

### 💻 Code

```ts
const a = true;
const b = 1;

function async(): number {
return b;
}

const first = a ? async() : 0;
// TS1005: '=>' expected.

const second = a ? async() : x => x;
// TS1005: ':' expected.
```

### 🙁 Actual behavior

The parser appears to interpret async() as the beginning of an async arrow function and the conditional separator as a return-type annotation.
The first case also produces a syntax diagnostic when parsed as JavaScript after removing the : number annotation. Node accepts and executes that JavaScript equivalent

### 🙂 Expected behavior

Both conditional expressions should parse successfully. async() is a call to the function named async, and the following colon separates the conditional’s branches.

### Additional information about the issue

Oxc fix: https://github.com/oxc-project/oxc/pull/26537

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two conditional-expression examples in the TypeScript parser and compare how async() is classified against an async arrow function. Use the linked Oxc fix as a reference for the relevant parsing behavior. Done means both examples parse successfully without the reported diagnostics, with regression coverage for the cases shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.