Skip to content

Commit 4cb8039

Browse files
committed
chore: unwrap ref type
1 parent 43f8afe commit 4cb8039

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/react.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import type { EffectScope, UnwrapNestedRefs } from '@vue/runtime-core'
1+
import type { EffectScope, Ref, UnwrapNestedRefs, UnwrapRef } from '@vue/runtime-core'
22
// @ts-expect-error setCurrentInstance not exposed
33
import { createHook, effectScope, isProxy, isRef, nextTick, provide, reactive, readonly, setCurrentInstance, unref, watch } from '@vue/runtime-core'
44
import { Fragment, createElement, useEffect, useRef, useState } from 'react'
55

66
import type { ReactivueInternalInstance } from './shared'
77
import { LifecycleHooks, getCurrentInstance, getEffects } from './shared'
88

9+
type ReturnedSetup<T> = T extends Readonly<Array<any>> ? T : T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>
10+
911
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
10-
export const getState = <T extends any>(setup: T): T extends Readonly<Array<any>> ? T : UnwrapNestedRefs<T> => isRef(setup) || isProxy(setup) || Array.isArray(setup) ? unref(setup) : typeof setup === 'object' ? readonly(reactive(setup as Object)) : setup as any
12+
export const getState = <T extends any>(setup: T): ReturnedSetup<T> => isRef(setup) || isProxy(setup) || Array.isArray(setup) ? unref(setup) : typeof setup === 'object' ? readonly(reactive(setup as Object)) : setup as any
1113

12-
type ReturnedSetup<T> = T extends Readonly<Array<any>> ? T : UnwrapNestedRefs<T>
1314
export function useSetup<State, Props = {}>(
1415
fn: (props: Props) => State,
1516
ReactProps: Props = {} as any,

0 commit comments

Comments
 (0)