Skip to content

Commit d0b849a

Browse files
committed
test(types): add test for ref/shallowRef generic casting
1 parent 9a57158 commit d0b849a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/dts-test/ref.test-d.ts

+16
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ const state = reactive({
163163

164164
expectType<string>(state.foo.label)
165165

166+
describe('ref with generic', <T extends { name: string }>() => {
167+
const r = {} as T
168+
const s = ref(r)
169+
expectType<string>(s.value.name)
170+
171+
const rr = {} as MaybeRef<T>
172+
// should at least allow casting
173+
const ss = ref(rr) as Ref<T>
174+
expectType<string>(ss.value.name)
175+
})
176+
166177
// shallowRef
167178
type Status = 'initial' | 'ready' | 'invalidating'
168179
const shallowStatus = shallowRef<Status>('initial')
@@ -206,6 +217,11 @@ describe('shallowRef with generic', <T extends { name: string }>() => {
206217
const s = shallowRef(r)
207218
expectType<string>(s.value.name)
208219
expectType<ShallowRef<T>>(shallowRef(r))
220+
221+
const rr = {} as MaybeRef<T>
222+
// should at least allow casting
223+
const ss = shallowRef(rr) as Ref<T> | ShallowRef<T>
224+
expectType<string>(ss.value.name)
209225
})
210226

211227
{

0 commit comments

Comments
 (0)