import { expectType } from 'tsd' import { Ref, ref, isRef, unref } from './index' function plainType(arg: number | Ref) { // ref coercing const coerced = ref(arg) expectType>(coerced) // isRef as type guard if (isRef(arg)) { expectType>(arg) } // ref unwrapping expectType(unref(arg)) // ref inner type should be unwrapped const nestedRef = ref({ foo: ref(1) }) expectType>(nestedRef) expectType<{ foo: number }>(nestedRef.value) // ref boolean const falseRef = ref(false) expectType>(falseRef) expectType(falseRef.value) // ref true const trueRef = ref(true) expectType>(trueRef) expectType(trueRef.value) // tuple expectType<[number, string]>(unref(ref([1, '1']))) interface IteratorFoo { [Symbol.iterator]: any } // with symbol expectType>( ref() ) } plainType(1) function bailType(arg: HTMLElement | Ref) { // ref coercing const coerced = ref(arg) expectType>(coerced) // isRef as type guard if (isRef(arg)) { expectType>(arg) } // ref unwrapping expectType(unref(arg)) // ref inner type should be unwrapped const nestedRef = ref({ foo: ref(document.createElement('DIV')) }) expectType>(nestedRef) expectType<{ foo: HTMLElement }>(nestedRef.value) } const el = document.createElement('DIV') bailType(el) function withSymbol() { const customSymbol = Symbol() const obj = { [Symbol.asyncIterator]: { a: 1 }, [Symbol.unscopables]: { b: '1' }, [customSymbol]: { c: [1, 2, 3] } } const objRef = ref(obj) expectType<{ a: number }>(objRef.value[Symbol.asyncIterator]) expectType<{ b: string }>(objRef.value[Symbol.unscopables]) expectType<{ c: Array }>(objRef.value[customSymbol]) } withSymbol()