Correct the SvelteComponent type

This commit is contained in:
Ryan Gossiaux
2022-02-16 14:58:52 -08:00
parent d7f6a58753
commit 10489a2723
3 changed files with 6 additions and 3 deletions

View File

@@ -82,7 +82,7 @@ const components = {
};
export type SupportedElement = keyof typeof components;
export type SupportedAs = SupportedElement | SvelteComponent;
export type SupportedAs = SupportedElement | typeof SvelteComponent;
export function getElementComponent(name: SupportedElement) {
return components[name];

View File

@@ -10,7 +10,7 @@
}
type SingleComponent =
| string
| [SvelteComponent, ComponentProps, TestRendererProps];
| [typeof SvelteComponent, ComponentProps, TestRendererProps];
export type TestRendererProps =
| undefined
| SingleComponent

View File

@@ -73,6 +73,7 @@
<script lang="ts">
import type { HTMLActionArray } from "$lib/hooks/use-actions";
import { forwardEventsBuilder } from "$lib/internal/forwardEventsBuilder";
import type { SvelteComponent } from "svelte";
const forwardEvents = forwardEventsBuilder(get_current_component());
type TSlotProps = $$Generic<{}>;
@@ -104,7 +105,9 @@
throw new Error(`<${name}> did not provide an \`as\` value to <Render>`);
}
let element = typeof as === "string" ? getElementComponent(as) : as;
// This type is a lie (could also be undefined) but there's a type error if we allow undefined
let element: typeof SvelteComponent =
typeof as === "string" ? getElementComponent(as) : as;
if (!element) {
throw new Error(
`<${name}> has an invalid or unsupported \`as\` prop: ${as}`