Skip to content

Commit

Permalink
fix(types): export INTERNAL interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Jul 13, 2022
1 parent 4d7edec commit 46aae7c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,13 +25,10 @@ const { useSyncExternalStore } = useSyncExternalStoreExports
// type Snapshot<T extends object> = ReturnType<SnapshotWrapper<T>['fn']>
//
// Using copy-paste types for now:
interface AsRef {
$$valtioRef: true
}
type AnyFunction = (...args: any[]) => any
type Snapshot<T> = T extends AnyFunction
? T
: T extends AsRef
: T extends INTERNAL_AsRef
? T
: T extends Promise<infer V>
? Snapshot<V>
Expand Down
6 changes: 2 additions & 4 deletions src/utils/proxyWithComputed.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -11,13 +12,10 @@ import { proxy, snapshot } from '../vanilla'
// type Snapshot<T extends object> = ReturnType<SnapshotWrapper<T>['fn']>
//
// Using copy-paste types for now:
interface AsRef {
$$valtioRef: true
}
type AnyFunction = (...args: any[]) => any
type Snapshot<T> = T extends AnyFunction
? T
: T extends AsRef
: T extends INTERNAL_AsRef
? T
: T extends Promise<infer V>
? Snapshot<V>
Expand Down
12 changes: 8 additions & 4 deletions src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends object>(o: T): T & AsRef {
export function ref<T extends object>(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 =>
Expand Down Expand Up @@ -247,7 +251,7 @@ export function subscribe<T extends object>(
type AnyFunction = (...args: any[]) => any
type Snapshot<T> = T extends AnyFunction
? T
: T extends AsRef
: T extends INTERNAL_AsRef
? T
: T extends Promise<infer V>
? Snapshot<V>
Expand Down

0 comments on commit 46aae7c

Please sign in to comment.