Skip to content

Svelte5: Improve type definitions for runes #11437

@ottomated

Description

@ottomated

Describe the problem

Typescript's intellisense lists every single function prototype property on runes:
image

This makes it difficult to see the actual useful properties (frozen, snapshot) and allows you to write things like

$state.bind(this);

without Typescript complaining.

Describe the proposed solution

The type definitions can be updated like so:

declare const $state: {
	/** @deprecated */
	apply: never;
	/** @deprecated */
	arguments: never;
	/** @deprecated */
	bind: never;
	/** @deprecated */
	call: never;
	/** @deprecated */
	caller: never;
	/** @deprecated */
	length: never;
	/** @deprecated */
	name: never;
	/** @deprecated */
	prototype: never;
	/** @deprecated */
	toString: never;

	<T>(initial: T): T;
	<T>(): T | undefined;

	frozen<T>(initial: T): Readonly<T>;
	frozen<T>(): Readonly<T> | undefined;
	 
	snapshot<T>(state: T): T;
};

which makes intellisense look like this:
image

with this tradeoff:
image

(note that I explored a few ways of achieving this and it seems fairly delicate)

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions