From 751f9420da98373c67173651d7942d62a9bb9c1e Mon Sep 17 00:00:00 2001 From: Ethan Palm <56270045+ethanpalm@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:07:42 -0700 Subject: [PATCH] add Twoslash info and example --- code.mdx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/code.mdx b/code.mdx index 9cdebff96..c89d9da7c 100644 --- a/code.mdx +++ b/code.mdx @@ -77,6 +77,35 @@ class HelloWorld { ``` ```` +### Twoslash + +In JavaScript and TypeScript code blocks, use `twoslash` to enable interactive type information. Users can hover over variables, functions, and parameters to see types and errors like in an IDE. + + +```ts title="Twoslash Example" twoslash +type Pet = "cat" | "dog" | "hamster"; + +function adoptPet(name: string, type: Pet) { + return `${name} the ${type} is now adopted!`; +} + +// Hover to see the inferred types +const message = adoptPet("Mintie", "cat"); +``` + +````mdx +```ts title="Twoslash Example" twoslash +type Pet = "cat" | "dog" | "hamster"; + +function adoptPet(name: string, type: Pet) { + return `${name} the ${type} is now adopted! 🎉`; +} + +// Hover to see the inferred types +const message = adoptPet("Mintie", "cat"); +``` +```` + ### Title Add a title to label your code example. Use `title="Your title"` or a string on a single line.