From fae36c9f5b794f255aca7abe0b94e079ebea586d Mon Sep 17 00:00:00 2001 From: Daishi Kato Date: Fri, 9 Feb 2024 11:15:22 +0900 Subject: [PATCH] [v2] export Snapshot type (#856) --- src/react.ts | 2 +- src/vanilla.ts | 8 +------- tests/snapshot.test.ts | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/react.ts b/src/react.ts index cb5a83f3..91cf9e8c 100644 --- a/src/react.ts +++ b/src/react.ts @@ -12,7 +12,7 @@ import { isChanged, } from 'proxy-compare' import { snapshot, subscribe } from './vanilla.ts' -import type { INTERNAL_Snapshot as Snapshot } from './vanilla.ts' +import type { Snapshot } from './vanilla.ts' const useAffectedDebugValue = ( state: object, diff --git a/src/vanilla.ts b/src/vanilla.ts index 99bd87a2..6601700d 100644 --- a/src/vanilla.ts +++ b/src/vanilla.ts @@ -28,7 +28,7 @@ type SnapshotIgnore = | AnyFunction | Primitive -type Snapshot = T extends { $$valtioSnapshot: infer S } +export type Snapshot = T extends { $$valtioSnapshot: infer S } ? S : T extends SnapshotIgnore ? T @@ -36,12 +36,6 @@ type Snapshot = T extends { $$valtioSnapshot: infer S } ? { readonly [K in keyof T]: Snapshot } : T -/** - * This is not a public API. - * It can be changed without any notice. - */ -export type INTERNAL_Snapshot = Snapshot - type CreateSnapshot = (target: T, version: number) => T type RemoveListener = () => void diff --git a/tests/snapshot.test.ts b/tests/snapshot.test.ts index ffaa85d0..3f492f24 100644 --- a/tests/snapshot.test.ts +++ b/tests/snapshot.test.ts @@ -1,7 +1,7 @@ import { createProxy, getUntracked } from 'proxy-compare' import { TypeEqual, expectType } from 'ts-expect' import { describe, expect, it } from 'vitest' -import { INTERNAL_Snapshot as Snapshot, proxy, snapshot } from 'valtio' +import { Snapshot, proxy, snapshot } from 'valtio' it('should return correct snapshots without subscribe', async () => { const child = proxy({ count: 0 })