Skip to content

Commit 3d83c9a

Browse files
sijie-ZRich-Harris
andauthored
fix: add bigint to Primitive type for $state.snapshot (#18388)
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 ```ts 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 --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 51baf1c commit 3d83c9a

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎.changeset/some-parts-watch.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: type BigInts in `$state.snapshot(...)` return values

‎packages/svelte/src/ambient.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ declare function $state<T>(initial: T): T;
2424
declare function $state<T>(): T | undefined;
2525

2626
declare namespace $state {
27-
type Primitive = string | number | boolean | null | undefined;
27+
type Primitive = string | number | bigint | boolean | null | undefined;
2828

2929
type TypedArray =
3030
| Int8Array

‎packages/svelte/types/index.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3229,7 +3229,7 @@ declare function $state<T>(initial: T): T;
32293229
declare function $state<T>(): T | undefined;
32303230

32313231
declare namespace $state {
3232-
type Primitive = string | number | boolean | null | undefined;
3232+
type Primitive = string | number | bigint | boolean | null | undefined;
32333233

32343234
type TypedArray =
32353235
| Int8Array

0 commit comments

Comments
 (0)