From c918f1b54b65256c796b005f7d63b648f4a61a45 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sat, 16 Apr 2022 00:55:35 -0500 Subject: [PATCH] Add render functions that ensure returned type is always a JSX element --- src/util/vue.tsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/util/vue.tsx b/src/util/vue.tsx index 7606e55..14700c4 100644 --- a/src/util/vue.tsx +++ b/src/util/vue.tsx @@ -71,6 +71,30 @@ export function renderCol(...objects: (VueFeature | CoercableComponent)[]): JSX. return {objects.map(render)}; } +export function renderJSX(object: VueFeature | CoercableComponent): JSX.Element { + if (isCoercableComponent(object)) { + if (typeof object === "function") { + return (object as JSXFunction)(); + } + if (typeof object === "string") { + return <>{object}; + } + // TODO why is object typed as never? + const Comp = object as DefineComponent; + return ; + } + const Component = object[ComponentKey]; + return ; +} + +export function renderRowJSX(...objects: (VueFeature | CoercableComponent)[]): JSX.Element { + return {objects.map(renderJSX)}; +} + +export function renderColJSX(...objects: (VueFeature | CoercableComponent)[]): JSX.Element { + return {objects.map(renderJSX)}; +} + export function isCoercableComponent(component: unknown): component is CoercableComponent { if (typeof component === "string") { return true;