Skip to content

Commit

Permalink
Add note about TypeScript requiring types for namespaced attributes (#…
Browse files Browse the repository at this point in the history
…954)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
titoBouzout and kodiakhq[bot] authored Dec 1, 2024
1 parent 534ce8a commit 89a1883
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/routes/configuration/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,15 @@ declare module "solid-js" {
count: number;
name: string;
}
interface ExplicitBoolAttributes {
disabled: boolean;
}
}
}

// Usage
<Input prop:name={name()} prop:count={count()}/>
<my-web-component attr:name={name()} attr:count={count()}/>
<my-web-component attr:name={name()} attr:count={count()} bool:disabled={true}/>
```

#### Custom directives
Expand Down
8 changes: 7 additions & 1 deletion src/routes/reference/jsx-attributes/attr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
title: attr:*
---

Forces the prop to be treated as an attribute instead of a property. Useful for Web Components where you want to set attributes.
Forces the prop to be treated as an attribute instead of a property.
Useful for Web Components where you want to set attributes.

```tsx
<my-element attr:status={props.status} />
```

<Callout type="info" title="Strong-Typing Custom Attributes">
Type definitions are required when using TypeScript.
See the[TypeScript](/configuration/typescript#forcing-properties-and-custom-attributes) page for examples.
</Callout>
5 changes: 5 additions & 0 deletions src/routes/reference/jsx-attributes/bool.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ This attribute is most useful for Web Components.
<my-element />

```

<Callout type="info" title="Strong-Typing Custom Bollean Attributes">
Type definitions are required when using TypeScript.
See the [TypeScript](/configuration/typescript#forcing-properties-and-custom-attributes) page for examples.
</Callout>
2 changes: 1 addition & 1 deletion src/routes/reference/jsx-attributes/on.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const handler = {

// or inline

<div on:click={{passive:true, handleEvent(e) => console.log("Weeeee!")}} />
<div on:click={{passive:true, handleEvent(e) { console.log("Weeeee!")}}} />
```

This new syntax replaces the now deprecated `oncapture:` and it's future proof for any posible new event listener options.
5 changes: 5 additions & 0 deletions src/routes/reference/jsx-attributes/prop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ Forces the prop to be treated as a property instead of an attribute.
```tsx
<div prop:scrollTop={props.scrollPos + "px"} />
```

<Callout type="info" title="Strong-Typing Custom Properties">
Type definitions are required when using TypeScript.
See the [TypeScript](/configuration/typescript#forcing-properties-and-custom-attributes) page for examples.
</Callout>

0 comments on commit 89a1883

Please sign in to comment.