muya 2.0.9 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muya",
3
- "version": "2.0.9",
3
+ "version": "2.1.0",
4
4
  "author": "samuel.gjabel@gmail.com",
5
5
  "repository": "https://github.com/samuelgjabel/muya",
6
6
  "main": "cjs/index.js",
package/src/types.ts CHANGED
@@ -14,7 +14,7 @@ export interface Cache<T> {
14
14
  export const EMPTY_SELECTOR = <T, S>(stateValue: T) => stateValue as unknown as S
15
15
 
16
16
  export interface GetState<T, IsFroMPromise extends boolean = false> {
17
- <S>(selector?: (stateValue: Awaited<T>) => S): Awaited<undefined extends S ? T : S>
17
+ <S>(selector?: (stateValue: Awaited<T>) => S): undefined extends S ? Awaited<T> : S
18
18
  /**
19
19
  * Get the cached state value.
20
20
  */
package/src/use-value.ts CHANGED
@@ -5,7 +5,7 @@ import { isError, isPromise } from './utils/is'
5
5
  export function useValue<T, S>(
6
6
  state: GetState<T>,
7
7
  selector: (stateValue: Awaited<T>) => S = EMPTY_SELECTOR,
8
- ): Awaited<undefined extends S ? T : S> {
8
+ ): undefined extends S ? Awaited<T> : S {
9
9
  const { emitter } = state
10
10
  const value = useSyncExternalStore<S>(
11
11
  state.emitter.subscribe,
@@ -21,5 +21,5 @@ export function useValue<T, S>(
21
21
  throw value
22
22
  }
23
23
 
24
- return value as Awaited<undefined extends S ? T : S>
24
+ return value as undefined extends S ? Awaited<T> : S
25
25
  }
package/types/types.d.ts CHANGED
@@ -11,7 +11,7 @@ export interface Cache<T> {
11
11
  }
12
12
  export declare const EMPTY_SELECTOR: <T, S>(stateValue: T) => S;
13
13
  export interface GetState<T, IsFroMPromise extends boolean = false> {
14
- <S>(selector?: (stateValue: Awaited<T>) => S): Awaited<undefined extends S ? T : S>;
14
+ <S>(selector?: (stateValue: Awaited<T>) => S): undefined extends S ? Awaited<T> : S;
15
15
  /**
16
16
  * Get the cached state value.
17
17
  */
@@ -1,2 +1,2 @@
1
1
  import { type GetState } from './types';
2
- export declare function useValue<T, S>(state: GetState<T>, selector?: (stateValue: Awaited<T>) => S): Awaited<undefined extends S ? T : S>;
2
+ export declare function useValue<T, S>(state: GetState<T>, selector?: (stateValue: Awaited<T>) => S): undefined extends S ? Awaited<T> : S;