From c9b65977f590a3a70312e5c57b69d1fc52eff660 Mon Sep 17 00:00:00 2001 From: bqqbarbhg Date: Thu, 26 Oct 2023 00:02:05 +0300 Subject: [PATCH] Fix JSX TypeScript type declarations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Allow returning arbitrary Child from function/class render - Add key to WithIntrinsicProps - Remove unnecessary ternary logic to preserve user's children type Co-authored-by: Teemu Pääkkönen --- jsx-runtime.d.ts | 6 +++--- src/kaiku.ts | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/jsx-runtime.d.ts b/jsx-runtime.d.ts index 98f96a3..0994b0b 100644 --- a/jsx-runtime.d.ts +++ b/jsx-runtime.d.ts @@ -1,13 +1,13 @@ -import { DefaultProps, NodeDescriptor } from './dist/kaiku' +import { DefaultProps, Child, NodeDescriptor } from './dist/kaiku' declare namespace JSX { type Element = NodeDescriptor type ArrayElement = Element[] interface FunctionElement { - (props: T): Element + (props: T): Child } interface ElementClass { - render(props: any): Element + render(props: T): Child } type ElementChildrenAttribute = { children: any diff --git a/src/kaiku.ts b/src/kaiku.ts index 3b4887c..f94d751 100644 --- a/src/kaiku.ts +++ b/src/kaiku.ts @@ -51,11 +51,10 @@ type HtmlElementProperties = Record & { } export type DefaultProps = Record -export type WithIntrinsicProps = T extends { - children: any +export type WithIntrinsicProps = T & { + children?: Child | Children + key?: string } - ? T - : T & { children?: Child | Children } type LazyProperty = T | (() => T) type ClassComponentDescriptor<