Skip to content

Commit

Permalink
fix: typo
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgja committed Nov 22, 2024
1 parent 4a0d6f0 commit 6a2fede
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muya",
"version": "2.0.3",
"version": "2.0.4",
"author": "[email protected]",
"repository": "https://github.com/samuelgjabel/muya",
"main": "cjs/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface Cache<T> {
export const EMPTY_SELECTOR = <T, S>(stateValue: T) => stateValue as unknown as S

export interface GetState<T> {
<S>(selector?: (stateValue: T) => S): undefined extends S ? T : S
<S>(selector?: (stateValue: T) => S): Awaited<undefined extends S ? T : S>
/**
* Get the cached state value.
*/
Expand Down
7 changes: 5 additions & 2 deletions packages/core/use-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { useDebugValue, useSyncExternalStore } from 'react'
import { EMPTY_SELECTOR, type GetState } from './types'
import { isError, isPromise } from './utils/is'

export function useValue<T, S>(state: GetState<T>, selector: (stateValue: T) => S = EMPTY_SELECTOR): undefined extends S ? T : S {
export function useValue<T, S>(
state: GetState<T>,
selector: (stateValue: T) => S = EMPTY_SELECTOR,
): Awaited<undefined extends S ? T : S> {
const { emitter } = state
const value = useSyncExternalStore<S>(
state.emitter.subscribe,
Expand All @@ -18,5 +21,5 @@ export function useValue<T, S>(state: GetState<T>, selector: (stateValue: T) =>
throw value
}

return value as undefined extends S ? T : S
return value as Awaited<undefined extends S ? T : S>
}

0 comments on commit 6a2fede

Please sign in to comment.