@ -1,6 +1,4 @@
declare module 'svelte' {
declare module 'svelte' {
// This should contain all the public interfaces (not all of them are actually importable, check current Svelte for which ones are).
/ * *
/ * *
* @deprecated Svelte components were classes in Svelte 4 . In Svelte 5 , thy are not anymore .
* @deprecated Svelte components were classes in Svelte 4 . In Svelte 5 , thy are not anymore .
* Use ` mount ` or ` createRoot ` instead to instantiate components .
* Use ` mount ` or ` createRoot ` instead to instantiate components .
@ -19,12 +17,36 @@ declare module 'svelte' {
$$inline? : boolean ;
$$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
/** Tooling for types uses this for properties are being used with `bind:` */
type PropsWithChildren < Props , Slots > = Props &
export type Binding < T > = { 'bind:' : T } ;
( Props extends { children? : any }
/ * *
? { }
* Tooling for types uses this for properties that may be bound to .
: Slots extends { default : any }
* Only use this if you author Svelte component type definition files by hand ( we recommend using ` @sveltejs/package ` instead ) .
? { children? : Snippet }
* Example :
* ` ` ` ts
* export class MyComponent extends SvelteComponent < { readonly : string , bindable : Bindable < string > } > { }
* ` ` `
* means you can now do ` <MyComponent {readonly} bind:bindable /> `
* /
export type Bindable < T > = T | Binding < T > ;
type WithBindings < T > = {
[ Key in keyof T ] : Bindable < T [ Key ] > ;
} ;
/ * *
* Utility type for ensuring backwards compatibility on a type level :
* - If there 's a default slot, add ' children ' to the props
* - All props are bindable
* /
type PropsWithChildren < Props , Slots > = WithBindings < Props > &
( Slots extends { default : any }
? // This is unfortunate because it means "accepts no props" turns into "accepts any prop"
// but the alternative is non-fixable type errors because of the way TypeScript index
// signatures work (they will always take precedence and make an impossible-to-satisfy children type).
Props extends Record < string , never >
? any
: { children? : any }
: { } ) ;
: { } ) ;
/ * *
/ * *
@ -56,7 +78,7 @@ declare module 'svelte' {
* for more info .
* for more info .
* /
* /
export class SvelteComponent <
export class SvelteComponent <
Props extends Record < string , any > = any ,
Props extends Record < string , any > = Record < string , any > ,
Events extends Record < string , any > = any ,
Events extends Record < string , any > = any ,
Slots extends Record < string , any > = any
Slots extends Record < string , any > = any
> {
> {
@ -75,7 +97,7 @@ declare module 'svelte' {
* Does not exist at runtime .
* Does not exist at runtime .
* # # # DO NOT USE !
* # # # DO NOT USE !
* * /
* * /
$$prop_def : PropsWithChildren< Props , Slots > ;
$$prop_def : RemoveBindable< Props > ; // Without PropsWithChildren: unnecessary, causes type bugs
/ * *
/ * *
* For type checking capabilities only .
* For type checking capabilities only .
* Does not exist at runtime .
* Does not exist at runtime .
@ -120,7 +142,7 @@ declare module 'svelte' {
* @deprecated Use ` SvelteComponent ` instead . See TODO for more information .
* @deprecated Use ` SvelteComponent ` instead . See TODO for more information .
* /
* /
export class SvelteComponentTyped <
export class SvelteComponentTyped <
Props extends Record < string , any > = any ,
Props extends Record < string , any > = Record < string , any > ,
Events extends Record < string , any > = any ,
Events extends Record < string , any > = any ,
Slots extends Record < string , any > = any
Slots extends Record < string , any > = any
> extends SvelteComponent < Props , Events , Slots > { }
> extends SvelteComponent < Props , Events , Slots > { }
@ -155,7 +177,7 @@ declare module 'svelte' {
* ` ` `
* ` ` `
* /
* /
export type ComponentProps < Comp extends SvelteComponent > =
export type ComponentProps < Comp extends SvelteComponent > =
Comp extends SvelteComponent < infer Props > ? Props : never ;
Comp extends SvelteComponent < infer Props > ? RemoveBindable< Props> : never ;
/ * *
/ * *
* Convenience type to get the type of a Svelte component . Useful for example in combination with
* Convenience type to get the type of a Svelte component . Useful for example in combination with
@ -225,6 +247,12 @@ declare module 'svelte' {
: [ type : Type , parameter : EventMap [ Type ] , options? : DispatchOptions ]
: [ type : Type , parameter : EventMap [ Type ] , options? : DispatchOptions ]
) : boolean ;
) : boolean ;
}
}
/** Anything except a function */
type NotFunction < T > = T extends Function ? never : T ;
type RemoveBindable < Props extends Record < string , any > > = {
[ Key in keyof Props ] : Props [ Key ] extends Bindable < infer Value > ? Value : Props [ Key ] ;
} ;
/ * *
/ * *
* The ` onMount ` function schedules a callback to run as soon as the component has been mounted to the DOM .
* The ` onMount ` function schedules a callback to run as soon as the component has been mounted to the DOM .
* It must be called during the component 's initialisation (but doesn' t need to live * inside * the component ;
* It must be called during the component 's initialisation (but doesn' t need to live * inside * the component ;
@ -295,8 +323,6 @@ declare module 'svelte' {
* Synchronously flushes any pending state changes and those that result from it .
* Synchronously flushes any pending state changes and those that result from it .
* * /
* * /
export function flushSync ( fn ? : ( ( ) = > void ) | undefined ) : void ;
export function flushSync ( fn ? : ( ( ) = > void ) | undefined ) : void ;
/** Anything except a function */
type NotFunction < T > = T extends Function ? never : T ;
/ * *
/ * *
* Mounts a component to the given target and returns the exports and potentially the props ( if compiled with ` accessors: true ` ) of the component
* Mounts a component to the given target and returns the exports and potentially the props ( if compiled with ` accessors: true ` ) of the component
*
*
@ -304,7 +330,7 @@ declare module 'svelte' {
export function mount < Props extends Record < string , any > , Exports extends Record < string , any > , Events extends Record < string , any > > ( component : ComponentType < SvelteComponent < Props , Events , any > > , options : {
export function mount < Props extends Record < string , any > , Exports extends Record < string , any > , Events extends Record < string , any > > ( component : ComponentType < SvelteComponent < Props , Events , any > > , options : {
target : Document | Element | ShadowRoot ;
target : Document | Element | ShadowRoot ;
anchor? : Node | undefined ;
anchor? : Node | undefined ;
props? : Props | undefined ;
props? : RemoveBindable< Props> | undefined ;
events ? : { [ Property in keyof Events ] : ( e : Events [ Property ] ) = > any ; } | undefined ;
events ? : { [ Property in keyof Events ] : ( e : Events [ Property ] ) = > any ; } | undefined ;
context? : Map < any , any > | undefined ;
context? : Map < any , any > | undefined ;
intro? : boolean | undefined ;
intro? : boolean | undefined ;
@ -315,7 +341,7 @@ declare module 'svelte' {
* * /
* * /
export function hydrate < Props extends Record < string , any > , Exports extends Record < string , any > , Events extends Record < string , any > > ( component : ComponentType < SvelteComponent < Props , Events , any > > , options : {
export function hydrate < Props extends Record < string , any > , Exports extends Record < string , any > , Events extends Record < string , any > > ( component : ComponentType < SvelteComponent < Props , Events , any > > , options : {
target : Document | Element | ShadowRoot ;
target : Document | Element | ShadowRoot ;
props? : Props | undefined ;
props? : RemoveBindable< Props> | undefined ;
events ? : { [ Property in keyof Events ] : ( e : Events [ Property ] ) = > any ; } | undefined ;
events ? : { [ Property in keyof Events ] : ( e : Events [ Property ] ) = > any ; } | undefined ;
context? : Map < any , any > | undefined ;
context? : Map < any , any > | undefined ;
intro? : boolean | undefined ;
intro? : boolean | undefined ;
@ -492,6 +518,18 @@ declare module 'svelte/compiler' {
* @param source The component source code
* @param source The component source code
* * /
* * /
export function compileModule ( source : string , options : ModuleCompileOptions ) : CompileResult ;
export function compileModule ( source : string , options : ModuleCompileOptions ) : CompileResult ;
/ * *
* The parse function parses a component , returning only its abstract syntax tree .
*
* The ` modern ` option ( ` false ` by default in Svelte 5 ) makes the parser return a modern AST instead of the legacy AST .
* ` modern ` will become ` true ` by default in Svelte 6 , and the option will be removed in Svelte 7 .
*
* https : //svelte.dev/docs/svelte-compiler#svelte-parse
* * /
export function parse ( source : string , options : {
filename? : string ;
modern : true ;
} ) : Root ;
/ * *
/ * *
* The parse function parses a component , returning only its abstract syntax tree .
* The parse function parses a component , returning only its abstract syntax tree .
*
*
@ -502,8 +540,8 @@ declare module 'svelte/compiler' {
* * /
* * /
export function parse ( source : string , options ? : {
export function parse ( source : string , options ? : {
filename? : string | undefined ;
filename? : string | undefined ;
modern? : boolean | undefined ;
modern? : false | undefined ;
} | undefined ) : Root | LegacyRoot;
} | undefined ) : LegacyRoot;
/ * *
/ * *
* @deprecated Replace this with ` import { walk } from 'estree-walker' `
* @deprecated Replace this with ` import { walk } from 'estree-walker' `
* * /
* * /