-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: integration guide for external libs
- Loading branch information
Showing
9 changed files
with
153 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Augmenting external JSX libraries | ||
|
||
typed-htmx is extremely minimal and requires the user to manually augment external JSX libraries that provide their own types. | ||
|
||
## Common guidance | ||
|
||
- Create a `types.d.ts` (any name is fine, as long as it ends in `.d.ts`) at the top of your src/ folder, | ||
or anywhere within the configured `include` of your tsconfig.json | ||
- Write a JSX element, e.g. `<div />`, and inspect its type | ||
- If you see React-related types, you are good to go | ||
- If not, try to discover the common namespace under which all HTML attributes go. | ||
|
||
Let's use [Hono](https://hono.dev/top) as an example. | ||
|
||
```tsx twoslash | ||
// @jsxImportSource: hono/jsx | ||
// In tsconfig.json, jsxImportSource = "hono/jsx" | ||
|
||
// The type we are augmenting in this case is `Hono.HTMLAttributes`. | ||
// hx-boost is not recognized as a proper attribute yet. | ||
<div hx-boost="bogus" /> | ||
//^? | ||
``` | ||
|
||
With this knowledge, we can now augment the type of `Hono.HTMLAttributes` assuming it is an interface: | ||
|
||
```tsx twoslash | ||
// @errors: 2322 | ||
// @jsxImportSource: hono/jsx | ||
/// <reference types="typed-htmx" /> | ||
|
||
declare global { | ||
namespace Hono { | ||
interface HTMLAttributes extends HtmxAttributes {} | ||
} | ||
} | ||
|
||
<div hx-boost="bogus" | ||
style={{}} | ||
/> | ||
``` | ||
|
||
## Hono | ||
|
||
```ts twoslash | ||
import 'typed-htmx'; | ||
|
||
declare global { | ||
namespace Hono { | ||
interface HTMLAttributes extends HtmxAttributes {} | ||
} | ||
} | ||
``` | ||
|
||
## Astro | ||
|
||
```ts twoslash | ||
import 'typed-htmx'; | ||
|
||
declare global { | ||
namespace astroHTML.JSX { | ||
interface IntrinsicAttributes extends HtmxAttributes {} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
{ | ||
"categoryOrder": ["core", "*"] | ||
"$schema": "https://typedoc.org/schema.json", | ||
"categoryOrder": ["core", "*"], | ||
"sourceLinkExternal": true, | ||
"excludeExternals": true, | ||
"externalPattern": [ | ||
"**/node_modules/**/*" | ||
], | ||
"readme": "bogus", | ||
"searchCategoryBoosts": { | ||
"Core": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.