Skip to content

Add note about TypeScript requiring types for namespaced attributes #954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading