Repository: mdx-js/mdx-analyzer
Pull request #450 (2024-06-23 17:17:00)

Fix compatibility with TypeScript 5.5
### Initial checklist

*   [x] I read the support docs <!-- https://github.com/unifiedjs/.github/blob/main/support.md -->
*   [x] I read the contributing guide <!-- https://github.com/unifiedjs/.github/blob/main/contributing.md -->
*   [x] I agree to follow the code of conduct <!-- https://github.com/unifiedjs/.github/blob/main/code-of-conduct.md -->
*   [x] I searched issues and couldn’t find anything (or linked relevant results below) <!-- https://github.com/search?q=user%3Aunifiedjs&type=Issues -->
*   [x] If applicable, I’ve added docs and tests

### Description of changes

This solution solves an upstream regression and is backwards compatible for our use case.

Refs https://github.com/microsoft/TypeScript/issues/58960

<!--do not edit: pr-->


changeset-bot[bot]: ###  🦋  Changeset detected

Latest commit: b24bf2d813af194752b75c4b129086bae6052839

**The changes in this PR will be included in the next version bump.**

<details><summary>This PR includes changesets to release 4 packages</summary>

  | Name                      | Type  |
| ------------------------- | ----- |
| @mdx-js/language-service  | Patch |
| @mdx-js/language-server   | Patch |
| @mdx-js/typescript-plugin | Patch |
| vscode-mdx                | Patch |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/mdx-js/mdx-analyzer/new/typescript-5.5?filename=.changeset/eighty-camels-sip.md&value=---%0A%22%40mdx-js%2Flanguage-service%22%3A%20patch%0A---%0A%0AFix%20compatibility%20with%20TypeScript%205.5%0A)


github-actions[bot]: Hi! This is accepted and can go somewhere!

Team: please review this PR and use the `area/*` (to describe the scope of the change), `platform/*` (if this is related to a specific one), and `semver/*` and `type/*` labels to annotate this.

<!--xxx:beep-boop:yes-maintainers-->

Patch:
diff --git a/.changeset/cold-turtles-divide.md b/.changeset/cold-turtles-divide.md
new file mode 100644
index 0000000..92e4c5f
--- /dev/null
+++ b/.changeset/cold-turtles-divide.md
@@ -0,0 +1,8 @@
+---
+'@mdx-js/language-service': patch
+'@mdx-js/language-server': patch
+'@mdx-js/typescript-plugin': patch
+'vscode-mdx': patch
+---
+
+Solve a regression caused by TypeScript 5.5
diff --git a/packages/language-service/lib/virtual-code.js b/packages/language-service/lib/virtual-code.js
index 050614e..8426ecc 100644
--- a/packages/language-service/lib/virtual-code.js
+++ b/packages/language-service/lib/virtual-code.js
@@ -90,7 +90,7 @@ export default function MDXContent(props) {
 }
 
 // @ts-ignore
-/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */
+/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */
 `
 
 const jsxIndent = '\n    '


Test patch:
diff --git a/packages/language-service/test/language-plugin.js b/packages/language-service/test/language-plugin.js
index 29e976f..474499a 100644
--- a/packages/language-service/test/language-plugin.js
+++ b/packages/language-service/test/language-plugin.js
@@ -98,7 +98,7 @@ test('create virtual code w/ mdxjsEsm', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -216,7 +216,7 @@ test('create virtual code w/ mdxjsEsm and CRLF', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -332,7 +332,7 @@ test('create virtual code w/o MDX layout in case of named re-export', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -449,7 +449,7 @@ test('create virtual code w/ MDX layout in case of default re-export', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -569,7 +569,7 @@ test('create virtual code w/ MDX layout in case of named and default re-export',
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -689,7 +689,7 @@ test('create virtual code w/ MDX layout in case of default and named re-export',
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -819,7 +819,7 @@ test('create virtual code w/ MDX layout in case of a default exported arrow func
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -954,7 +954,7 @@ test('create virtual code w/ MDX layout in case of a default exported function d
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -1071,7 +1071,7 @@ test('create virtual code w/ MDX layout in case of a default exported constant',
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -1206,7 +1206,7 @@ test('create virtual code w/ MDX layout and matching argument name', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -1345,7 +1345,7 @@ test('create virtual code w/ MDX layout in case of a default export followed by
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -1484,7 +1484,7 @@ test('create virtual code w/ MDX layout in case of a default export preceded by
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -1599,7 +1599,7 @@ test('create virtual code w/ mdxFlowExpression', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -1715,7 +1715,7 @@ test('create virtual code w/ empty mdxFlowExpression', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -1861,7 +1861,7 @@ test('create virtual code w/ prefixed JSX expressions for mdxFlowExpression', ()
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -2015,7 +2015,7 @@ test('create virtual code w/ prefixed JSX expressions in attributes', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -2188,7 +2188,7 @@ test('create virtual code w/ mdxJsxFlowElement w/ children', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -2330,7 +2330,7 @@ test('create virtual code w/ mdxJsxFlowElement w/ blockquote child', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -2471,7 +2471,7 @@ test('create virtual code w/ mdxJsxFlowElement w/o children', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -2617,7 +2617,7 @@ test('create virtual code w/ mdxJsxTextElement', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -2743,7 +2743,7 @@ test('create virtual code w/ mdxTextExpression', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -2865,7 +2865,7 @@ test('create virtual code w/ async mdxTextExpression', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -3030,7 +3030,7 @@ test('ignore async functions in props or expressions', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -3150,7 +3150,7 @@ test('create virtual code w/ dedented markdown content', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -3256,7 +3256,7 @@ test('create virtual code w/ syntax error', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -3342,7 +3342,7 @@ test('create virtual code w/ yaml frontmatter', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -3474,7 +3474,7 @@ test('update virtual code', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -3615,7 +3615,7 @@ test('support checkMdx', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },
@@ -3715,7 +3715,7 @@ test('support custom jsxImportSource', () => {
         '}',
         '',
         '// @ts-ignore',
-        '/** @typedef {(0 extends 1 & Props ? {} : Props) & {components?: {}}} MDXContentProps */',
+        '/** @typedef {(void extends Props ? {} : Props) & {components?: {}}} MDXContentProps */',
         ''
       )
     },