fix: adjust broken types

The generated types were invalid TypeScript ("cannot use unique symbol at this position"). Use utility types to ensure the types are not unpacked during type generation.
Leftover from #9988
pull/10327/head
Simon Holthausen 11 months ago
parent d309a9d47a
commit 0279546e02

@ -2759,7 +2759,7 @@ export function spread_props(...props) {
* @template {Record<string, any>} Props
* @template {Record<string, any> | undefined} Exports
* @template {Record<string, any>} Events
* @param {typeof import('../../main/public.js').SvelteComponent<Props, Events>} component
* @param {import('../../main/public.js').ComponentType<import('../../main/public.js').SvelteComponent<Props, Events>>} component
* @param {{
* target: Node;
* props?: Props;
@ -2809,7 +2809,7 @@ export function createRoot(component, options) {
* @template {Record<string, any>} Props
* @template {Record<string, any> | undefined} Exports
* @template {Record<string, any>} Events
* @param {typeof import('../../main/public.js').SvelteComponent<Props, Events>} component
* @param {import('../../main/public.js').ComponentType<import('../../main/public.js').SvelteComponent<Props, Events>>} component
* @param {{
* target: Node;
* props?: Props;

@ -34,7 +34,7 @@ export function createClassComponent(options) {
* @template {Record<string, any>} Slots
*
* @param {import('../main/public.js').SvelteComponent<Props, Events, Slots>} component
* @returns {typeof import('../main/public.js').SvelteComponent<Props, Events, Slots> & Exports}
* @returns {import('../main/public.js').ComponentType<import('../main/public.js').SvelteComponent<Props, Events, Slots> & Exports>}
*/
export function asClassComponent(component) {
// @ts-expect-error $$prop_def etc are not actually defined

@ -30,7 +30,7 @@ export function asClassComponent(component) {
html: result.html
};
};
// this is present for SSR
// @ts-expect-error this is present for SSR
component_constructor.render = _render;
// @ts-ignore

@ -23,7 +23,7 @@ type PropsWithChildren<Props, Slots> = Props &
(Props extends { children?: any }
? {}
: Slots extends { default: any }
? { children?: Snippet<[]> }
? { children?: Snippet }
: {});
/**

@ -24,7 +24,7 @@ declare module 'svelte' {
(Props extends { children?: any }
? {}
: Slots extends { default: any }
? { children?: Snippet<[]> }
? { children?: Snippet }
: {});
/**
@ -321,15 +321,7 @@ declare module 'svelte' {
* If you don't need to interact with the component after mounting, use `mount` instead to save some bytes.
*
* */
export function createRoot<Props extends Record<string, any>, Exports extends Record<string, any> | undefined, Events extends Record<string, any>>(component: {
new (options: ComponentConstructorOptions<Props & (Props extends {
children?: any;
} ? {} : {} | {
children?: ((this: void) => unique symbol & {
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
}) | undefined;
})>): SvelteComponent<Props, Events, any>;
}, options: {
export function createRoot<Props extends Record<string, any>, Exports extends Record<string, any> | undefined, Events extends Record<string, any>>(component: ComponentType<SvelteComponent<Props, Events, any>>, options: {
target: Node;
props?: Props | undefined;
events?: Events | undefined;
@ -346,15 +338,7 @@ declare module 'svelte' {
* If you need to interact with the component after mounting, use `createRoot` instead.
*
* */
export function mount<Props extends Record<string, any>, Exports extends Record<string, any> | undefined, Events extends Record<string, any>>(component: {
new (options: ComponentConstructorOptions<Props & (Props extends {
children?: any;
} ? {} : {} | {
children?: ((this: void) => unique symbol & {
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
}) | undefined;
})>): SvelteComponent<Props, Events, any>;
}, options: {
export function mount<Props extends Record<string, any>, Exports extends Record<string, any> | undefined, Events extends Record<string, any>>(component: ComponentType<SvelteComponent<Props, Events, any>>, options: {
target: Node;
props?: Props | undefined;
events?: Events | undefined;
@ -1734,17 +1718,7 @@ declare module 'svelte/legacy' {
* @deprecated Use this only as a temporary solution to migrate your imperative component code to Svelte 5.
*
* */
export function asClassComponent<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>>(component: SvelteComponent<Props, Events, Slots>): {
new (options: ComponentConstructorOptions<Props & (Props extends {
children?: any;
} ? {} : Slots extends {
default: any;
} ? {
children?: ((this: void) => unique symbol & {
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
}) | undefined;
} : {})>): SvelteComponent<Props, Events, Slots>;
} & Exports;
export function asClassComponent<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>>(component: SvelteComponent<Props, Events, Slots>): ComponentType<SvelteComponent<Props, Events, Slots> & Exports>;
// This should contain all the public interfaces (not all of them are actually importable, check current Svelte for which ones are).
/**
@ -1770,7 +1744,7 @@ declare module 'svelte/legacy' {
(Props extends { children?: any }
? {}
: Slots extends { default: any }
? { children?: Snippet<[]> }
? { children?: Snippet }
: {});
/**
@ -1859,6 +1833,34 @@ declare module 'svelte/legacy' {
$set(props: Partial<Props>): void;
}
/**
* Convenience type to get the type of a Svelte component. Useful for example in combination with
* dynamic components using `<svelte:component>`.
*
* Example:
* ```html
* <script lang="ts">
* import type { ComponentType, SvelteComponent } from 'svelte';
* import Component1 from './Component1.svelte';
* import Component2 from './Component2.svelte';
*
* const component: ComponentType = someLogic() ? Component1 : Component2;
* const componentOfCertainSubType: ComponentType<SvelteComponent<{ needsThisProp: string }>> = someLogic() ? Component1 : Component2;
* </script>
*
* <svelte:component this={component} />
* <svelte:component this={componentOfCertainSubType} needsThisProp="hello" />
* ```
*/
type ComponentType<Comp extends SvelteComponent = SvelteComponent> = (new (
options: ComponentConstructorOptions<
Comp extends SvelteComponent<infer Props> ? Props : Record<string, any>
>
) => Comp) & {
/** The custom element version of the component. Only present if compiled with the `customElement` compiler option */
element?: typeof HTMLElement;
};
const SnippetReturn: unique symbol;
/**

Loading…
Cancel
Save