Skip to content

Commit

Permalink
Define the jsx namespace in the ./jsx-runtime module
Browse files Browse the repository at this point in the history
  • Loading branch information
ryota-ka committed Jul 10, 2024
1 parent afd8432 commit e534a8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ Just like built-in modules, you can pass an arbitrary value to your custom modul
Unlike built-in modules, we have no assumptions on what kind of values should be passed to custom modules. You have to augment `jsx.CustomModules` interface so that it will typecheck.

```ts
declare module '@herp-inc/snabbdom-jsx' {
declare module '@herp-inc/snabbdom-jsx/jsx-runtime' {
namespace jsx {
interface CustomModules {
// Add your custom modules here
Expand Down
14 changes: 0 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
import type { Attrs, Classes, Dataset, On, Props } from 'snabbdom';

import type Snabbdom from './jsx-runtime';

declare namespace jsx {
interface CustomModules {
attrs: Attrs;
class: Classes;
dataset: Dataset;
props: Props;
on: On;
style: Snabbdom.Style;
}
}

// eslint-disable-next-line import/no-default-export
export default Snabbdom;
export type { jsx };
13 changes: 11 additions & 2 deletions src/jsx-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type * as CSS from 'csstype';
import type { Attrs, Classes, Dataset, Hooks, Key, On, Props, VNode, VNodeData } from 'snabbdom';

import type { jsx } from '.';

// eslint-disable-next-line @typescript-eslint/ban-types
type Whatever = string & {};

Expand Down Expand Up @@ -1110,6 +1108,17 @@ declare namespace JSX {
}
}

declare namespace jsx {
interface CustomModules {
attrs: Attrs;
class: Classes;
dataset: Dataset;
props: Props;
on: On;
style: Snabbdom.Style;
}
}

const isArrayChildren = (children: Snabbdom.Node): children is readonly Snabbdom.Node[] => Array.isArray(children);

const kebab2camel = (kebab: string): string => {
Expand Down

0 comments on commit e534a8c

Please sign in to comment.