microsoft / microsoft/TypeScript-TmLanguage

Bad syntax Highlighting in TS when using multiline union types

Open
#1,043 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
471
Forks
149
PR merge metrics
No merged PRs in 30d

Description

Does this issue occur when all extensions are disabled?: Yes/No

  • VS Code Version: 1.95.3
  • OS Version: MacOS 15.0.1

Steps to Reproduce:

Write the following in VSCode

let myObj:
    | {
          prop1: string
      }
    | {
          prop2: string
      }
function myFunc() {}

The syntax of function myFunc() {} and everything after it is broken.

I found that it happens only in this rare edge case. Some things that actually fix it:

  1. Adding a semicolon
let myObj:
    | {
          prop1: string
      }
    | {
          prop2: string
      };
function myFunc() {}
  1. Writing the union type on a single line
let myObj: { prop1: string } | { prop2: string }
function myFunc() {}
  1. Adding a line break before the next line of code
let myObj:
    | {
          prop1: string
      }
    | {
          prop2: string
      }

function myFunc() {}

Bad highlighting:
Image

Wanted highlighting:
Image

Contributor guide

No contributing guide indexed for this repository

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 TypeScript snippet in VS Code and inspect the repository's TextMate grammar files to locate handling for multiline union types. Done means the following function is highlighted correctly without requiring a semicolon or an extra blank line.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.