Skip to content

Svelte5: Improve type definitions for runes #11437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ottomated opened this issue May 2, 2024 · 1 comment · Fixed by #11439
Closed

Svelte5: Improve type definitions for runes #11437

ottomated opened this issue May 2, 2024 · 1 comment · Fixed by #11439

Comments

@ottomated
Copy link
Contributor

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

@ottomated ottomated changed the title Svelte5: Svelte5: Improve type definitions for runes May 2, 2024
@AdrianGonz97
Copy link
Member

AdrianGonz97 commented May 2, 2024

Pretty clever! Riffing off of this a bit, perhaps this could work too? REPL

Applying it to the namespace instead should curb the tradeoff issue altogether:
img

@dummdidumm dummdidumm added this to the 5.0 milestone May 3, 2024
dummdidumm added a commit that referenced this issue May 3, 2024
…lisense

Ensures that IDEs will order the to the bottom so that the rune variants are on top, better visible

closes #11437
dummdidumm added a commit that referenced this issue May 3, 2024
…lisense (#11439)

Ensures that IDEs will order the to the bottom so that the rune variants are on top, better visible

closes #11437
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants