Skip to content

Commit

Permalink
test(types): add test for ref/shallowRef generic casting
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 16, 2023
1 parent 9a57158 commit d0b849a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/dts-test/ref.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ const state = reactive({

expectType<string>(state.foo.label)

describe('ref with generic', <T extends { name: string }>() => {
const r = {} as T
const s = ref(r)
expectType<string>(s.value.name)

const rr = {} as MaybeRef<T>
// should at least allow casting
const ss = ref(rr) as Ref<T>
expectType<string>(ss.value.name)
})

// shallowRef
type Status = 'initial' | 'ready' | 'invalidating'
const shallowStatus = shallowRef<Status>('initial')
Expand Down Expand Up @@ -206,6 +217,11 @@ describe('shallowRef with generic', <T extends { name: string }>() => {
const s = shallowRef(r)
expectType<string>(s.value.name)
expectType<ShallowRef<T>>(shallowRef(r))

const rr = {} as MaybeRef<T>
// should at least allow casting
const ss = shallowRef(rr) as Ref<T> | ShallowRef<T>
expectType<string>(ss.value.name)
})

{
Expand Down

0 comments on commit d0b849a

Please sign in to comment.