Repository: TypeScript
Issue: tsserver and intellisense hang indefinitely on "loading intellisense status" and "loading..." when using assertion function and complex conditional type
Labels: Bug,Rescheduled

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

tsserver typescript langauge server loading intellisense status indefinite error forever asserts assertion function vscode conditional type

<!--
  What search terms did you use when trying to find an existing bug report?
  List them here so people in the future can find this one more easily.
-->

### 🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->
- This changed between versions `4.7.4` and `4.8.0-beta` and happens in all versions up to `4.9.0-dev.20221015`

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior

  The TypeScript Workbench can be used for more complex setups, try
  https://www.typescriptlang.org/dev/bug-workbench/

  As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
Unfortunately, painstakingly copy-pasting all the types from the various packages into the playground doesn't allow me to reproduce the issue. So instead, I've created a minimal example repository that demonstrates the issue: https://github.com/Xunnamius/mre-typescript-issue-51188

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```typescript
import { visit, SKIP, type Visitor } from 'unist-util-visit';

import type { Content as MdastContent } from 'mdast';

function assertNonNullable<T>(
  value: T,
  err: string
): asserts value is NonNullable<T> {
  if (value === null) {
    throw new Error(err);
  }
}

export function visitAndReveal<Tree extends MdastContent>(
  tree: Tree,
  visitor?: Visitor,
  reverse?: boolean
) {
  visit(
    tree,
    'hidden',
    (node, index, parent) => {
      // UNCOMMENTING THIS WILL KILL INTELLISENSE
      // assertNonNullable(
      //   index,
      //   'error while revealing hidden node: node index is missing'
      // );

      // UNCOMMENTING THIS WILL KILL INTELLISENSE
      // assertNonNullable(
      //  parent,
      //  'error while revealing hidden node: node parent is missing'
      //);

      return visitor?.(node, index, parent) ?? [SKIP, index];
    },
    reverse
  );
}
```

### 🙁 Actual behavior

Tsserver and intellisense in vscode (latest version) hang when using a TypeScript version `>=4.8.0-beta`. See video example below.

### 🙂 Expected behavior

Tsserver/intellisense does not hang in latest versions of vscode and TypeScript.

---

https://user-images.githubusercontent.com/656017/195998496-e83d5c99-dc27-4867-8bcc-aa3d6a54ff55.mp4