Skip to content

Commit

Permalink
Merge pull request #4 from ammarahm-ed/add-typescript-support
Browse files Browse the repository at this point in the history
Fix ItemTemplate events typings
  • Loading branch information
ClassicOldSong authored Jan 17, 2023
2 parents f509a41 + 5eae0b8 commit 04a4eba
Show file tree
Hide file tree
Showing 3 changed files with 1,443 additions and 59 deletions.
23 changes: 20 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Style } from "@nativescript/core";
import { Style, ViewBase } from "@nativescript/core";
import {
Document,
DOMEvent,
HTMLElementTagNameMap,
Node,
NSComponentsMap,
NSCustomComponentsMap,
PseudoElementsMap
} from "dominative";
import { JSX as SolidJSX } from "solid-js";

Expand All @@ -28,7 +29,7 @@ import { JSX as SolidJSX } from "solid-js";
* Read more about the render function here:
* @link https://www.solidjs.com/docs/latest#render
*/
export function render(app: () => JSX.Element, root: Node):void;
export function render(app: () => JSX.Element, root: Node): void;

export type Filter<
Set,
Expand All @@ -39,6 +40,15 @@ export type MapNativeViewEvents<T, C> = {
[K in T as `on:${K}`]: (event: DOMEvent<C>) => void;
};

export type MapPseudoElementEvents<T, C> = {
[K in T as `on:${K}`]: (event: {
view?: ViewBase;
index?: number;
item?: any;
data?: any
}) => void;
};

type NSComponentEventsMap = {
[K in keyof NSComponentsMap]: MapNativeViewEvents<
HTMLElementTagNameMap[K]["eventNames"],
Expand All @@ -49,6 +59,13 @@ type NSComponentEventsMap = {
NSCustomComponentsMap[K]["eventNames"],
NSCustomComponentsMap[K]
>;
} & {
[K in keyof Pick<PseudoElementsMap, "ItemTemplate">]: MapPseudoElementEvents<
"createView" | "itemLoading",
PseudoElementsMap[K]
>;
} & {
[K in keyof Omit<PseudoElementsMap, "ItemTemplate">]: {};
};

export type IgnoredKeys =
Expand Down Expand Up @@ -196,7 +213,7 @@ declare global {
interface CustomCaptureEvents {}

type JSXElementAttributes<K> = SolidJSX.CustomAttributes<
NSComponentsMap[K]
NSComponentsMap[K]
> &
Partial<
DefineNSComponent<HTMLElementTagNameMap[K], NSComponentEventsMap[K]> &
Expand Down
Loading

0 comments on commit 04a4eba

Please sign in to comment.