Correct the SvelteComponent type
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
}
|
||||
type SingleComponent =
|
||||
| string
|
||||
| [SvelteComponent, ComponentProps, TestRendererProps];
|
||||
| [typeof SvelteComponent, ComponentProps, TestRendererProps];
|
||||
export type TestRendererProps =
|
||||
| undefined
|
||||
| SingleComponent
|
||||
|
||||
@@ -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}`
|
||||
|
||||
Reference in New Issue
Block a user