Skip to content

Commit 29e09f3

Browse files
test(types): add test case
1 parent 7da94ea commit 29e09f3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

types/test/v3/reactivity-test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import {
1313
markRaw,
1414
shallowReadonly,
1515
set,
16-
del
16+
del,
17+
ShallowRef
1718
} from '../../index'
18-
import { IsUnion, describe, expectType } from '../utils'
19+
import { IsUnion, describe, expectType, expectError } from '../utils'
1920

2021
function plainType(arg: number | Ref<number>) {
2122
// ref coercing
@@ -163,6 +164,15 @@ if (shallowStatus.value === 'initial') {
163164
shallowStatus.value = 'invalidating'
164165
}
165166

167+
{
168+
// should return ShallowRef<T> | Ref<T>, not ShallowRef<T | Ref<T>>
169+
expectType<ShallowRef<{ name: string }> | Ref<{ name: string }>>(
170+
shallowRef({} as { name: string } | Ref<{ name: string }>)
171+
)
172+
expectType<ShallowRef<number> | Ref<string[]> | ShallowRef<string>>(
173+
shallowRef('' as Ref<string[]> | string | number)
174+
)
175+
}
166176
const refStatus = ref<Status>('initial')
167177
if (refStatus.value === 'initial') {
168178
expectType<Ref<Status>>(shallowStatus)
@@ -386,7 +396,6 @@ describe('set/del', () => {
386396
del([], 'fse', 123)
387397
})
388398

389-
390399
{
391400
//#12978
392401
type Steps = { step: '1' } | { step: '2' }
@@ -395,4 +404,4 @@ describe('set/del', () => {
395404

396405
expectType<IsUnion<typeof shallowUnionGenParam>>(false)
397406
expectType<IsUnion<typeof shallowUnionAsCast>>(false)
398-
}
407+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy