Skip to content

Conversation

baseballyama
Copy link
Member

@baseballyama baseballyama commented Jan 12, 2025

The Svelte 5 compiler throws an error if a $derived value is reassigned. For object values, it’s better to use const instead of let. This will be addressed by #985

<script>
  let count = $state(1);
	let double = $derived(count * 2);

	let obj = $state({ foo: 1 });
	let derivedObj = $derived( { ...obj, bar: true });

	function invalid() {
		double = double + 1;
		derivedObj.bar = false;
	}
</script>

https://svelte.dev/playground/hello-world?version=5.17.3#H4sIAAAAAAAAE22PwU7EMAxEf8WyOLRQBZVjdheJGzc-gHBIGlfKKptUiVtAVf8dZdstHLhZM2_G9oxBXwglvpL3ET5j8hYqso7J1thg7zxllO8z8vdQuCJgc0u9DIPIE3kumtGZ_tO7GJgCZ5R4zF1yAz-rAOCJoYtjYDjBXWbNVLX1QQXFxbFxNJ6KZSm5iWy1svfwdIU2LJrzb3yGPkYJLSx_etb028rdumAGIUQ05waMThI4jbSlguJ-DB27GMCFSXtnqxrmoiver9qGB2gPm7PvEUYnOEGvfaaruahwfNwfxwaZvhhl2bl8LD9gOIRsggEAAA==

Copy link

pkg-pr-new bot commented Jan 12, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eslint-plugin-svelte@1014

commit: b4eb6bf

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great! Thank you!

@ota-meshi ota-meshi merged commit 74373ec into main Jan 14, 2025
18 checks passed
@ota-meshi ota-meshi deleted the chore/no-reactive-reassign branch January 14, 2025 05:06
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 this pull request may close these issues.

2 participants