From c4f06aed076c0528fab080531b34d7c6a3c7c0a5 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Mon, 3 Jun 2019 21:09:51 +0200 Subject: [PATCH] fix: don't use typeof check for h --- src/index.d.ts | 17 +++++++++++++---- test/ts/preact.tsx | 5 ++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 91eb963cdb2..d50b6ff00df 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -150,7 +150,16 @@ declare namespace preact { export import JSX = JSXInternal; } - type h = typeof createElement; + function h( + type: string, + props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record | null, + ...children: ComponentChildren[] + ): VNode; + function h

( + type: ComponentType

, + props: Attributes & P | null, + ...children: ComponentChildren[] + ): VNode; namespace h { export import JSX = JSXInternal; } @@ -200,12 +209,12 @@ declare namespace preact { diffed?(vnode: VNode): void; /** Attach a hook that is invoked after an error is caught in a component but before calling lifecycle hooks */ catchError?(error: any, component: Component): void; - /** + /** * Attach a hook that is invoked after an error is caught while executing render. - * + * * When this hook returns true, the diffing on the affected vnode will be stopped. * When this hook returns false, the error will be thrown (and thus passed to catchError or lifecycle hooks) - * + * * @return Return a boolean indicating whether the error was handled by the hook or not */ catchRender?(error: any, component: Component): boolean; diff --git a/test/ts/preact.tsx b/test/ts/preact.tsx index 5e7b3d1fe9b..399cc2e93f6 100644 --- a/test/ts/preact.tsx +++ b/test/ts/preact.tsx @@ -1,4 +1,4 @@ -import { createElement, render, Component, FunctionalComponent, AnyComponent } from "../../src"; +import { createElement, render, Component, FunctionalComponent, AnyComponent, h } from "../../src"; interface DummyProps { initialInput: string; @@ -42,6 +42,9 @@ function DummerComponent({ input, initialInput }: DummerComponentProps) { render(createElement('div', { title: "test", key: "1" }), document); render(createElement(DummyComponent, { initialInput: "The input", key: "1" }), document); render(createElement(DummerComponent, { initialInput: "The input", input: "New input", key: "1"}), document); +render(h('div', { title: "test", key: "1" }), document); +render(h(DummyComponent, { initialInput: "The input", key: "1" }), document); +render(h(DummerComponent, { initialInput: "The input", input: "New input", key: "1"}), document); // Accessing children const ComponentWithChildren: FunctionalComponent = (