@@ -72,12 +72,12 @@ type UseOnyxOptions<TKey extends OnyxKey, TReturnValue> = BaseUseOnyxOptions & U
7272
7373type FetchStatus = 'loading' | 'loaded' ;
7474
75- type ResultMetadata = {
75+ type ResultMetadata < TValue > = {
7676 status : FetchStatus ;
77- sourceValue ?: OnyxValue < OnyxKey > ;
77+ sourceValue ?: NonNullable < TValue > | undefined ;
7878} ;
7979
80- type UseOnyxResult < TValue > = [ NonNullable < TValue > | undefined , ResultMetadata ] ;
80+ type UseOnyxResult < TValue > = [ NonNullable < TValue > | undefined , ResultMetadata < TValue > ] ;
8181
8282/**
8383 * Gets the cached value from the Onyx cache. If the key is a collection key, it will return all the values in the collection.
@@ -160,7 +160,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
160160 const shouldGetCachedValueRef = useRef ( true ) ;
161161
162162 // Inside useOnyx.ts, we need to track the sourceValue separately
163- const sourceValueRef = useRef < OnyxValue < OnyxKey > | undefined > ( undefined ) ;
163+ const sourceValueRef = useRef < NonNullable < TReturnValue > | undefined > ( undefined ) ;
164164
165165 useEffect ( ( ) => {
166166 // These conditions will ensure we can only handle dynamic collection member keys from the same collection.
@@ -325,7 +325,8 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
325325 // Signals that we want to get the newest cached value again in `getSnapshot()`.
326326 shouldGetCachedValueRef . current = true ;
327327
328- sourceValueRef . current = sourceValue ;
328+ // sourceValue is unknown type, so we need to cast it to the correct type.
329+ sourceValueRef . current = sourceValue as NonNullable < TReturnValue > ;
329330
330331 // Finally, we signal that the store changed, making `getSnapshot()` be called again.
331332 onStoreChange ( ) ;
0 commit comments