Skip to content

Commit

Permalink
fix: do not refer to typed-html in main decl
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed Jan 3, 2024
1 parent c2b23e2 commit 20ff7ca
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"typed-htmx": "link:.."
},
"devDependencies": {
"@types/react": "^18.2.15"
"hono": "^3.11.12"
}
}
27 changes: 6 additions & 21 deletions example/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
11 changes: 11 additions & 0 deletions example/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// typed-htmx declares mostly ambient types so this is all you need.
import 'typed-htmx';

// A demo of how to augment foreign types with htmx attributes.
// In this case, Hono sources its types from its own namespace, so we do the same
// and directly extend its namespace.
declare global {
namespace Hono {
interface HTMLAttributes extends HtmxAttributes {}
}
}
18 changes: 11 additions & 7 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
{
"files": ["index.jsx"],
"compilerOptions": {
"target": "es6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "jsx": "react", /* Specify what JSX code is generated. */
"jsx": "react-jsx" /* Specify what JSX code is generated. */,
"jsxImportSource": "typed-htmx/typed-html",
"module": "commonjs",
// "jsx": "react",
"jsx": "react-jsx", /* Specify what JSX code is generated. */
// If your frontend framework prescribes a JSX source, change it here.
// In this example, we will use Hono.
"jsxImportSource": "hono/jsx",
"module": "node16",
"moduleResolution": "node16" /* Specify how TypeScript looks up a file from a given module specifier. */,
"types": ["typed-htmx"],
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
"checkJs": true /* Enable error reporting in type-checked JavaScript files. */,
"rootDir": ".",
"outDir": "./dist",
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */,
"skipDefaultLibCheck": true /* Skip type checking .d.ts files that are included with TypeScript. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
},
"include": [
"src/**/*",
]
}
11 changes: 8 additions & 3 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="typed-html" />

/**
* Provides type definitions in JSX for htmx attributes.
* @module
Expand Down Expand Up @@ -160,10 +158,17 @@ interface HtmxBuiltinExtensions {
morphdom: "morphdom";
}

/**
* Alternative attribute variants recognized by htmx.
*/
type HtmxData<T> = {
[K in keyof T as K extends `hx-${string}` ? `data-${K}` : never]: T[K]
}

/**
* Definitions for htmx attributes up to 1.9.3.
*/
interface HtmxAttributes {
interface HtmxAttributes extends HtmxData<HtmxAttributes> {
/** @ignore For React compatibility only. */
children?: {};
/** @ignore For React compatibility only. */
Expand Down

0 comments on commit 20ff7ca

Please sign in to comment.