microsoft / microsoft/TypeScript

Disallow newline after `as` after function instantiation

Open
#55,806 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Parser Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

as newline ASI function type parameters spec difference

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVJxwB4AVAPgAoBKALnhIChRJYFUoBbEAZwAcowCAGLwA3vBAAPXjhgZ4GAJ68EAcxAYMIGPAC88KKkXwAvk3DQ48CBoPc6hxQwY35kvQRzwi8AEzwyOwYhADp1TW0GIA

💻 Code
let x = foo < 2 > as
F.getter
🙁 Actual behavior

It is parsed as

let x = foo<2> as F.getter;
🙂 Expected behavior

It should be parsed as

let x = (foo < 2) > as;
F.getter;
Additional information about the issue

The linked code is valid JavaScript code, and it would be great if tsc could parse as such.

I know that TS is not in general a syntactic superset of JavaScript, but both Babel and SWC already parse this example (when in TS mode) according to JS semantics. We could change our parsers, but it would be better if this ambiguity could be solved in tsc.

cc @kdy1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the parsing difference using the linked TypeScript Playground and the provided code sample, then trace how the TypeScript parser handles as across a newline after function instantiation. Done means the sample follows the expected JavaScript/ASI parse while existing TypeScript parsing behavior remains covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.