Correct the SvelteComponent type
This commit is contained in:
@@ -82,7 +82,7 @@ const components = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type SupportedElement = keyof typeof components;
|
export type SupportedElement = keyof typeof components;
|
||||||
export type SupportedAs = SupportedElement | SvelteComponent;
|
export type SupportedAs = SupportedElement | typeof SvelteComponent;
|
||||||
|
|
||||||
export function getElementComponent(name: SupportedElement) {
|
export function getElementComponent(name: SupportedElement) {
|
||||||
return components[name];
|
return components[name];
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
}
|
}
|
||||||
type SingleComponent =
|
type SingleComponent =
|
||||||
| string
|
| string
|
||||||
| [SvelteComponent, ComponentProps, TestRendererProps];
|
| [typeof SvelteComponent, ComponentProps, TestRendererProps];
|
||||||
export type TestRendererProps =
|
export type TestRendererProps =
|
||||||
| undefined
|
| undefined
|
||||||
| SingleComponent
|
| SingleComponent
|
||||||
|
|||||||
@@ -73,6 +73,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLActionArray } from "$lib/hooks/use-actions";
|
import type { HTMLActionArray } from "$lib/hooks/use-actions";
|
||||||
import { forwardEventsBuilder } from "$lib/internal/forwardEventsBuilder";
|
import { forwardEventsBuilder } from "$lib/internal/forwardEventsBuilder";
|
||||||
|
import type { SvelteComponent } from "svelte";
|
||||||
const forwardEvents = forwardEventsBuilder(get_current_component());
|
const forwardEvents = forwardEventsBuilder(get_current_component());
|
||||||
|
|
||||||
type TSlotProps = $$Generic<{}>;
|
type TSlotProps = $$Generic<{}>;
|
||||||
@@ -104,7 +105,9 @@
|
|||||||
throw new Error(`<${name}> did not provide an \`as\` value to <Render>`);
|
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) {
|
if (!element) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`<${name}> has an invalid or unsupported \`as\` prop: ${as}`
|
`<${name}> has an invalid or unsupported \`as\` prop: ${as}`
|
||||||
|
|||||||
Reference in New Issue
Block a user