镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Bad syntax Highlighting in TS when using multiline union types #1043

Open

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

Activity

  1. vs-code-engineering commented on Nov 29, 2024

    @vs-code-engineering

    Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.95.3. Please try upgrading to the latest version and checking whether this issue remains.

    Happy Coding!

  2. RedCMD commented on Nov 29, 2024

    @RedCMD

    Add something like |(?=function\\s) to type-annotation should work

    Image

    Image

  3. tgroutars commented on Dec 12, 2024

    @tgroutars
    Author

    It's not just functions, anything that comes after it has bad syntax highlighting unfortunately

  4. saltire commented on Jan 23, 2025

    @saltire

    Here is another example, if needed. The first test1 function renders correctly, but the second test2 function does not.

    function testFunc<A, B>(fn: (arg3: string) => void): any {
      // ...
    }
    
    const test1 = testFunc<
      string,
      string
    >(async (arg3: string) => {
      const abc = 1;
      return abc.toString();
    });
    
    const testObj = {
      test2: testFunc<
        string,
        string
      >(async (arg3: string) => {
        const abc = 1;
        return abc.toString();
      }),
    };
    

    This is the result in Monokai. Notice how the keywords async, const and return are incorrect, as well as the closing > in the generic type.

    Image

    In some themes there are further issues; in One Monokai, notice the abc variable and toString function.

    Image

  5. removed their assignment
    on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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