From 39d6ed05aa1e77f2f68e1415a6bb94d0ea50b81f Mon Sep 17 00:00:00 2001 From: "S. Elliott Johnson" Date: Sun, 14 Jan 2024 17:52:00 -0700 Subject: [PATCH] fix: Honestly idk why it was broken but it's fixed now --- packages/svelte/src/main/private.d.ts | 12 ++++++ packages/svelte/src/main/public.d.ts | 9 +---- packages/svelte/types/index.d.ts | 57 +++++++++------------------ 3 files changed, 31 insertions(+), 47 deletions(-) diff --git a/packages/svelte/src/main/private.d.ts b/packages/svelte/src/main/private.d.ts index 54f9869178..a560223297 100644 --- a/packages/svelte/src/main/private.d.ts +++ b/packages/svelte/src/main/private.d.ts @@ -1,4 +1,16 @@ +import type { Snippet } from './public'; + /** * Anything except a function */ export type NotFunction = T extends Function ? never : T; + +// Utility type for ensuring backwards compatibility on a type level: If there's a default slot, add 'children' to the props if it doesn't exist there already +// if you're curious why this is here and not declared as an unexported type from `public.d.ts`, try putting it there +// and see what happens in the output `index.d.ts` -- it breaks, presumably because of a TypeScript compiler bug. +export type PropsWithChildren = Props & + (Props extends { children?: any } + ? {} + : Slots extends { default: any } + ? { children?: Snippet<[]> } + : {}); diff --git a/packages/svelte/src/main/public.d.ts b/packages/svelte/src/main/public.d.ts index dfb4f6b38a..17f6d3b2a5 100644 --- a/packages/svelte/src/main/public.d.ts +++ b/packages/svelte/src/main/public.d.ts @@ -18,14 +18,6 @@ export interface ComponentConstructorOptions< $$inline?: boolean; } -// Utility type for ensuring backwards compatibility on a type level: If there's a default slot, add 'children' to the props if it doesn't exist there already -type PropsWithChildren = Props & - (Props extends { children?: any } - ? {} - : Slots extends { default: any } - ? { children?: Snippet } - : {}); - /** * Can be used to create strongly typed Svelte components. * @@ -229,3 +221,4 @@ export interface EventDispatcher> { export * from './main-client.js'; import './ambient.js'; +import type { PropsWithChildren } from './private.js'; diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 98461ce731..ab90811cf8 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -19,14 +19,6 @@ declare module 'svelte' { $$inline?: boolean; } - // Utility type for ensuring backwards compatibility on a type level: If there's a default slot, add 'children' to the props if it doesn't exist there already - type PropsWithChildren = Props & - (Props extends { children?: any } - ? {} - : Slots extends { default: any } - ? { children?: Snippet } - : {}); - /** * Can be used to create strongly typed Svelte components. * @@ -319,6 +311,14 @@ declare module 'svelte' { * Anything except a function */ type NotFunction = T extends Function ? never : T; + + // Utility type for ensuring backwards compatibility on a type level: If there's a default slot, add 'children' to the props if it doesn't exist there already + type PropsWithChildren = Props & + (Props extends { children?: any } + ? {} + : Slots extends { default: any } + ? { children?: Snippet<[]> } + : {}); /** * Mounts the given component to the given target and returns a handle to the component's public accessors * as well as a `$set` and `$destroy` method to update the props of the component or destroy it. @@ -327,13 +327,7 @@ declare module 'svelte' { * * */ export function createRoot, Exports extends Record | undefined, Events extends Record>(component: { - new (options: ComponentConstructorOptions unique symbol & { - _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\""; - }) | undefined; - })>): SvelteComponent; + new (options: ComponentConstructorOptions>): SvelteComponent; }, options: { target: Node; props?: Props | undefined; @@ -352,13 +346,7 @@ declare module 'svelte' { * * */ export function mount, Exports extends Record | undefined, Events extends Record>(component: { - new (options: ComponentConstructorOptions unique symbol & { - _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\""; - }) | undefined; - })>): SvelteComponent; + new (options: ComponentConstructorOptions>): SvelteComponent; }, options: { target: Node; props?: Props | undefined; @@ -1730,15 +1718,7 @@ declare module 'svelte/legacy' { * * */ export function asClassComponent, Exports extends Record, Events extends Record, Slots extends Record>(component: SvelteComponent): { - new (options: ComponentConstructorOptions unique symbol & { - _: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\""; - }) | undefined; - } : {})>): SvelteComponent; + new (options: ComponentConstructorOptions>): SvelteComponent; } & Exports; // This should contain all the public interfaces (not all of them are actually importable, check current Svelte for which ones are). @@ -1760,14 +1740,6 @@ declare module 'svelte/legacy' { $$inline?: boolean; } - // Utility type for ensuring backwards compatibility on a type level: If there's a default slot, add 'children' to the props if it doesn't exist there already - type PropsWithChildren = Props & - (Props extends { children?: any } - ? {} - : Slots extends { default: any } - ? { children?: Snippet } - : {}); - /** * Can be used to create strongly typed Svelte components. * @@ -1877,6 +1849,13 @@ declare module 'svelte/legacy' { _: 'functions passed to {@render ...} tags must use the `Snippet` type imported from "svelte"'; }; }; + // Utility type for ensuring backwards compatibility on a type level: If there's a default slot, add 'children' to the props if it doesn't exist there already + type PropsWithChildren = Props & + (Props extends { children?: any } + ? {} + : Slots extends { default: any } + ? { children?: Snippet<[]> } + : {}); } declare module 'svelte/motion' {