From: Evan You Date: Sat, 16 Dec 2023 05:46:11 +0000 (+0800) Subject: test(types): add test for ref/shallowRef generic casting X-Git-Tag: v3.3.12~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0b849ac39bcfae37a6f2e96756f0b0e47ddaa09;p=thirdparty%2Fvuejs%2Fcore.git test(types): add test for ref/shallowRef generic casting --- diff --git a/packages/dts-test/ref.test-d.ts b/packages/dts-test/ref.test-d.ts index f66ff92690..62bad77c2e 100644 --- a/packages/dts-test/ref.test-d.ts +++ b/packages/dts-test/ref.test-d.ts @@ -163,6 +163,17 @@ const state = reactive({ expectType(state.foo.label) +describe('ref with generic', () => { + const r = {} as T + const s = ref(r) + expectType(s.value.name) + + const rr = {} as MaybeRef + // should at least allow casting + const ss = ref(rr) as Ref + expectType(ss.value.name) +}) + // shallowRef type Status = 'initial' | 'ready' | 'invalidating' const shallowStatus = shallowRef('initial') @@ -206,6 +217,11 @@ describe('shallowRef with generic', () => { const s = shallowRef(r) expectType(s.value.name) expectType>(shallowRef(r)) + + const rr = {} as MaybeRef + // should at least allow casting + const ss = shallowRef(rr) as Ref | ShallowRef + expectType(ss.value.name) }) {