Skip to content

Commit 43fb9e8

Browse files
Fix TS errors in reference/astro-syntax.mdx (#14237)
Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
1 parent d85ffdd commit 43fb9e8

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

src/content/docs/en/reference/astro-syntax.mdx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Local variables can be used in curly braces to pass attribute values to both HTM
3535

3636
```astro title="src/components/DynamicAttributes.astro" "{name}" "${name}"
3737
---
38+
import MyComponent from "./MyComponent.astro";
3839
const name = "Astro";
3940
---
4041
<h1 class={name}>Attribute expressions are supported</h1>
@@ -66,7 +67,7 @@ Instead, use a client-side script to add the event handler, like you would in va
6667
function handleClick () {
6768
console.log("button clicked!");
6869
}
69-
document.getElementById("button").addEventListener("click", handleClick);
70+
document.getElementById("button")?.addEventListener("click", handleClick);
7071
</script>
7172
```
7273
:::
@@ -243,7 +244,7 @@ A callback function passed as `<Shout />`’s child will receive the all-caps `m
243244
import Shout from "../components/Shout.astro";
244245
---
245246
<Shout message="slots!">
246-
{(message) => <div>{message}</div>}
247+
{(message: string) => <div>{message}</div>}
247248
</Shout>
248249
249250
<!-- renders as <div>SLOTS!</div> -->
@@ -254,7 +255,7 @@ Callback functions can be passed to named slots inside a wrapping HTML element t
254255
```astro
255256
<Shout message="slots!">
256257
<fragment slot="message">
257-
{(message) => <div>{message}</div>}
258+
{(message: string) => <div>{message}</div>}
258259
</fragment>
259260
</Shout>
260261
```
@@ -265,23 +266,24 @@ Use a standard HTML element for the wrapping tag or any lowercase tag (e.g. `<fr
265266

266267
`Astro.self` allows Astro components to be recursively called. This behavior lets you render an Astro component from within itself by using `<Astro.self>` in the component template. This can help iterate over large data stores and nested data structures.
267268

268-
```astro
269+
```astro title="src/components/NestedList.astro" {14}
269270
---
270-
// NestedList.astro
271+
type Props = {
272+
items: (string | string[])[];
273+
};
271274
const { items } = Astro.props;
272275
---
276+
273277
<ul class="nested-list">
274-
{items.map((item) => (
275-
<li>
276-
<!-- If there is a nested data-structure we render `<Astro.self>` -->
277-
<!-- and can pass props through with the recursive call -->
278-
{Array.isArray(item) ? (
279-
<Astro.self items={item} />
280-
) : (
281-
item
282-
)}
283-
</li>
284-
))}
278+
{
279+
items.map((item) => (
280+
<li>
281+
{/* If there is a nested data-structure we render `<Astro.self>` */}
282+
{/* and can pass props through with the recursive call */}
283+
{Array.isArray(item) ? <Astro.self items={item} /> : item}
284+
</li>
285+
))
286+
}
285287
</ul>
286288
```
287289

@@ -307,4 +309,4 @@ And would render HTML like this:
307309
</li>
308310
<li>D</li>
309311
</ul>
310-
```
312+
```

0 commit comments

Comments
 (0)