import { WritableComputedRef } from '@vue/reactivity' import { expectType, ref, computed, Ref, ComputedRef } from './index' import 'vue/ref-macros' import { RefType, RefTypes } from 'vue/ref-macros' // wrapping refs // normal let n = $(ref(1)) n = 2 // @ts-expect-error n = 'foo' // #4499 nullable let msg = $(ref(null)) msg = 'hello world' msg = null expectType(msg![RefType]) // computed let m = $(computed(() => n + 1)) m * 1 // @ts-expect-error m.slice() expectType(m[RefType]) // writable computed let wc = $( computed({ get: () => n + 1, set: v => (n = v - 1) }) ) wc = 2 // @ts-expect-error wc = 'foo' expectType(wc[RefType]) // destructure function useFoo() { let x = $ref(1) let y = $computed(() => 'hi') return $$({ x, y, z: 123 }) } const fooRes = useFoo() const { x, y, z } = $(fooRes) expectType(x) expectType(y) expectType(z) // $ref expectType($ref(1)) expectType($ref(ref(1))) expectType<{ foo: number }>($ref({ foo: ref(1) })) // $shallowRef expectType($shallowRef(1)) expectType<{ foo: Ref }>($shallowRef({ foo: ref(1) })) // $computed expectType($computed(() => 1)) let b = $ref(1) expectType( $computed(() => b, { onTrack() {} }) ) // writable computed expectType( $computed({ get: () => 1, set: () => {} }) ) // $$ const xRef = $$(x) expectType>(xRef) const yRef = $$(y) expectType>(yRef) const c = $computed(() => 1) const cRef = $$(c) expectType>(cRef) const c2 = $computed({ get: () => 1, set: () => {} }) const c2Ref = $$(c2) expectType>(c2Ref) // $$ on object const obj = $$({ n, m, wc }) expectType>(obj.n) expectType>(obj.m) expectType>(obj.wc)