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 <hello@rich-harris.dev>
pull/18389/head
sijie-Z 1 month ago committed by GitHub
parent 51baf1c1af
commit 3d83c9abe6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: type BigInts in `$state.snapshot(...)` return values

@ -24,7 +24,7 @@ declare function $state<T>(initial: T): T;
declare function $state<T>(): T | undefined;
declare namespace $state {
type Primitive = string | number | boolean | null | undefined;
type Primitive = string | number | bigint | boolean | null | undefined;
type TypedArray =
| Int8Array

@ -3229,7 +3229,7 @@ declare function $state<T>(initial: T): T;
declare function $state<T>(): T | undefined;
declare namespace $state {
type Primitive = string | number | boolean | null | undefined;
type Primitive = string | number | bigint | boolean | null | undefined;
type TypedArray =
| Int8Array

Loading…
Cancel
Save