Skip to content

fix: add bigint to Primitive type for $state.snapshot#18388

Merged
Rich-Harris merged 2 commits into
sveltejs:mainfrom
sijie-Z:fix/bigint-snapshot-type
Jun 5, 2026
Merged

fix: add bigint to Primitive type for $state.snapshot#18388
Rich-Harris merged 2 commits into
sveltejs:mainfrom
sijie-Z:fix/bigint-snapshot-type

Conversation

@sijie-Z

@sijie-Z sijie-Z commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #18385

Problem

$state.snapshot infers BigInt properties as never because bigint is missing
from the Primitive type definition. BigInt is a valid JavaScript primitive and is
supported by structuredClone.

Solution

Added bigint to the Primitive type in both packages/svelte/src/ambient.d.ts and
packages/svelte/types/index.d.ts.

Before

const object = $state({ number: 1n });
const snapshot = $state.snapshot(object);
// snapshot.number is inferred as never ❌

After

const object = $state({ number: 1n });
const snapshot = $state.snapshot(object);
// snapshot.number is correctly inferred as bigint ✅

Tests and linting

- [x] This is a type-only change, no runtime behavior affected

BigInt is a valid JavaScript primitive and is supported by structuredClone.
Adding it to the Primitive type ensures that .snapshot correctly
infers BigInt properties instead of resolving to never.

Fixes sveltejs#18385
@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 42ba325

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sijie-Z

sijie-Z commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

This is a type-only change that doesn't affect runtime behavior. No changeset needed.

@Rich-Harris

Copy link
Copy Markdown
Member

Thank you. Type changes need changesets too! Otherwise they won't trigger a patch release (they'll have to wait for something else to do so) and won't show up in the changelog

@Rich-Harris Rich-Harris merged commit 3d83c9a into sveltejs:main Jun 5, 2026
15 of 16 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 5, 2026
@sijie-Z

sijie-Z commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Ah, I see! Thank you so much for the explanation, Rich. I didn't realize that type-only changes also required a changeset to trigger the patch release. I'll definitely keep this in mind for future contributions.

Thrilled to have my first PR merged into Svelte! 🧡

Rich-Harris pushed a commit that referenced this pull request Jun 7, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## svelte@5.56.3

### Patch Changes

- fix: ignore errors that occur in destroyed effects
([#18384](#18384))

- fix: type BigInts in `$state.snapshot(...)` return values
([#18388](#18388))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@sacrosanctic

Copy link
Copy Markdown
Contributor

Ah, I see! Thank you so much for the explanation, Rich. I didn't realize that type-only changes also required a changeset to trigger the patch release. I'll definitely keep this in mind for future contributions.

Thrilled to have my first PR merged into Svelte! 🧡

@sijie-Z For additional context. It's not about types vs no types. It's internal vs external. Internal types doesn't need a changeset. Since these types are external, they're exposed to the user, and a changeset is needed.

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.

$state.snapshot with BigInt properties infer as never

3 participants