From 1c336ae143fb5974cfa34f96e8322a04938975b0 Mon Sep 17 00:00:00 2001 From: Gary Bernhardt Date: Wed, 19 Sep 2018 13:56:15 -0700 Subject: [PATCH] Reverse order of overloaded h() type definitions For overloaded functions, TypeScript reports errors based on the last of the overloaded definitions. For `h`'s overloaded definitions, the string version is currently last. When type checking of an `h` call fails (for example, due to a missing prop, or due to an incorrect prop type), TypeScript simply says "Argument of type 'typeof OurComponent' is not assignable to parameter of type 'string'." This patch switches the order of the `h` definitions, so that the h

version comes last. This makes TypeScript report a more specific error that will include missing props, etc. --- src/preact.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/preact.d.ts b/src/preact.d.ts index 3682ee7f8b..7d5384f14d 100644 --- a/src/preact.d.ts +++ b/src/preact.d.ts @@ -101,16 +101,16 @@ declare namespace preact { abstract render(props?: RenderableProps

, state?: Readonly, context?: any): ComponentChild; } - function h

( - node: ComponentFactory

, - params: Attributes & P | null, - ...children: ComponentChildren[] - ): VNode; function h( node: string, params: JSX.HTMLAttributes & JSX.SVGAttributes & Record | null, ...children: ComponentChildren[] ): VNode; + function h

( + node: ComponentFactory

, + params: Attributes & P | null, + ...children: ComponentChildren[] + ): VNode; function render(node: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment, mergeWith?: Element): Element; function rerender(): void;