From 46aae7cd5cd513dff1a009a3462c20247d17b86c Mon Sep 17 00:00:00 2001 From: daishi Date: Wed, 13 Jul 2022 22:31:12 +0900 Subject: [PATCH] fix(types): export INTERNAL interface --- src/react.ts | 6 ++---- src/utils/proxyWithComputed.ts | 6 ++---- src/vanilla.ts | 12 ++++++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/react.ts b/src/react.ts index 018259e0..672b7ac1 100644 --- a/src/react.ts +++ b/src/react.ts @@ -10,6 +10,7 @@ import { // The following is a workaround until ESM is supported. import useSyncExternalStoreExports from 'use-sync-external-store/shim' import { snapshot, subscribe } from './vanilla' +import type { INTERNAL_AsRef } from './vanilla' const { useSyncExternalStore } = useSyncExternalStoreExports @@ -24,13 +25,10 @@ const { useSyncExternalStore } = useSyncExternalStoreExports // type Snapshot = ReturnType['fn']> // // Using copy-paste types for now: -interface AsRef { - $$valtioRef: true -} type AnyFunction = (...args: any[]) => any type Snapshot = T extends AnyFunction ? T - : T extends AsRef + : T extends INTERNAL_AsRef ? T : T extends Promise ? Snapshot diff --git a/src/utils/proxyWithComputed.ts b/src/utils/proxyWithComputed.ts index 1e264f06..0bac708c 100644 --- a/src/utils/proxyWithComputed.ts +++ b/src/utils/proxyWithComputed.ts @@ -1,4 +1,5 @@ import { proxy, snapshot } from '../vanilla' +import type { INTERNAL_AsRef } from '../vanilla' // Unfortunately, this doesn't work with tsc. // Hope to find a solution to make this work. @@ -11,13 +12,10 @@ import { proxy, snapshot } from '../vanilla' // type Snapshot = ReturnType['fn']> // // Using copy-paste types for now: -interface AsRef { - $$valtioRef: true -} type AnyFunction = (...args: any[]) => any type Snapshot = T extends AnyFunction ? T - : T extends AsRef + : T extends INTERNAL_AsRef ? T : T extends Promise ? Snapshot diff --git a/src/vanilla.ts b/src/vanilla.ts index 71255996..cf922daf 100644 --- a/src/vanilla.ts +++ b/src/vanilla.ts @@ -7,13 +7,17 @@ const HANDLER = __DEV__ ? Symbol('HANDLER') : Symbol() const PROMISE_RESULT = __DEV__ ? Symbol('PROMISE_RESULT') : Symbol() const PROMISE_ERROR = __DEV__ ? Symbol('PROMISE_ERROR') : Symbol() -interface AsRef { +/** + * This not a public API. + * It can be changed without notice. + */ +export interface INTERNAL_AsRef { $$valtioRef: true } const refSet = new WeakSet() -export function ref(o: T): T & AsRef { +export function ref(o: T): T & INTERNAL_AsRef { refSet.add(o) - return o as T & AsRef + return o as T & INTERNAL_AsRef } const isObject = (x: unknown): x is object => @@ -247,7 +251,7 @@ export function subscribe( type AnyFunction = (...args: any[]) => any type Snapshot = T extends AnyFunction ? T - : T extends AsRef + : T extends INTERNAL_AsRef ? T : T extends Promise ? Snapshot