Skip to content

Commit 4e23edf

Browse files
authored
add Twoslash info and example (#1356)
1 parent 46d1a79 commit 4e23edf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

code.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,35 @@ class HelloWorld {
7777
```
7878
````
7979

80+
### Twoslash
81+
82+
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.
83+
84+
85+
```ts title="Twoslash Example" twoslash
86+
type Pet = "cat" | "dog" | "hamster";
87+
88+
function adoptPet(name: string, type: Pet) {
89+
return `${name} the ${type} is now adopted!`;
90+
}
91+
92+
// Hover to see the inferred types
93+
const message = adoptPet("Mintie", "cat");
94+
```
95+
96+
````mdx
97+
```ts title="Twoslash Example" twoslash
98+
type Pet = "cat" | "dog" | "hamster";
99+
100+
function adoptPet(name: string, type: Pet) {
101+
return `${name} the ${type} is now adopted! 🎉`;
102+
}
103+
104+
// Hover to see the inferred types
105+
const message = adoptPet("Mintie", "cat");
106+
```
107+
````
108+
80109
### Title
81110

82111
Add a title to label your code example. Use `title="Your title"` or a string on a single line.

0 commit comments

Comments
 (0)