|
1 | | -import{ |
2 | | -ref, |
3 | | -readonly, |
4 | | -shallowReadonly, |
5 | | -describe, |
6 | | -expectError, |
7 | | -expectType, |
8 | | -Ref, |
9 | | -reactive, |
10 | | -markRaw |
11 | | -}from'./index' |
12 | | - |
13 | | -describe('should support DeepReadonly',()=>{ |
14 | | -constr=readonly({obj: {k: 'v'}}) |
15 | | -// @ts-expect-error |
16 | | -expectError((r.obj={})) |
17 | | -// @ts-expect-error |
18 | | -expectError((r.obj.k='x')) |
19 | | -}) |
20 | | - |
21 | | -// #4180 |
22 | | -describe('readonly ref',()=>{ |
23 | | -constr=readonly(ref({count: 1})) |
24 | | -expectType<Ref>(r) |
25 | | -}) |
26 | | - |
27 | | -describe('should support markRaw',()=>{ |
28 | | -classTest<T>{ |
29 | | -item={}asRef<T> |
30 | | -} |
31 | | -consttest=newTest<number>() |
32 | | -constplain={ |
33 | | -ref: ref(1) |
34 | | -} |
35 | | - |
36 | | -constr=reactive({ |
37 | | -class: { |
38 | | -raw: markRaw(test), |
39 | | -reactive: test |
40 | | -}, |
41 | | -plain: { |
42 | | -raw: markRaw(plain), |
43 | | -reactive: plain |
44 | | -} |
45 | | -}) |
46 | | - |
47 | | -expectType<Test<number>>(r.class.raw) |
48 | | -// @ts-expect-error it should unwrap |
49 | | -expectType<Test<number>>(r.class.reactive) |
50 | | - |
51 | | -expectType<Ref<number>>(r.plain.raw.ref) |
52 | | -// @ts-expect-error it should unwrap |
53 | | -expectType<Ref<number>>(r.plain.reactive.ref) |
54 | | -}) |
55 | | - |
56 | | -describe('shallowReadonly ref unwrap',()=>{ |
57 | | -constr=shallowReadonly({count: {n: ref(1)}}) |
58 | | -// @ts-expect-error |
59 | | -r.count=2 |
60 | | -expectType<Ref>(r.count.n) |
61 | | -r.count.n.value=123 |
62 | | -}) |
63 | | - |
64 | | -// #3819 |
65 | | -describe('should unwrap tuple correctly',()=>{ |
66 | | -constreadonlyTuple=[ref(0)]asconst |
67 | | -constreactiveReadonlyTuple=reactive(readonlyTuple) |
68 | | -expectType<Ref<number>>(reactiveReadonlyTuple[0]) |
69 | | - |
70 | | -consttuple: [Ref<number>]=[ref(0)] |
71 | | -constreactiveTuple=reactive(tuple) |
72 | | -expectType<Ref<number>>(reactiveTuple[0]) |
73 | | -}) |
| 1 | +import{ |
| 2 | +ref, |
| 3 | +readonly, |
| 4 | +shallowReadonly, |
| 5 | +describe, |
| 6 | +expectError, |
| 7 | +expectType, |
| 8 | +Ref, |
| 9 | +reactive, |
| 10 | +markRaw |
| 11 | +}from'./index' |
| 12 | + |
| 13 | +describe('should support DeepReadonly',()=>{ |
| 14 | +constr=readonly({obj: {k: 'v'}}) |
| 15 | +// @ts-expect-error |
| 16 | +expectError((r.obj={})) |
| 17 | +// @ts-expect-error |
| 18 | +expectError((r.obj.k='x')) |
| 19 | +}) |
| 20 | + |
| 21 | +// #4180 |
| 22 | +describe('readonly ref',()=>{ |
| 23 | +constr=readonly(ref({count: 1})) |
| 24 | +expectType<Ref>(r) |
| 25 | +}) |
| 26 | + |
| 27 | +describe('should support markRaw',()=>{ |
| 28 | +classTest<T>{ |
| 29 | +item={}asRef<T> |
| 30 | +} |
| 31 | +consttest=newTest<number>() |
| 32 | +constplain={ |
| 33 | +ref: ref(1) |
| 34 | +} |
| 35 | + |
| 36 | +constr=reactive({ |
| 37 | +class: { |
| 38 | +raw: markRaw(test), |
| 39 | +reactive: test |
| 40 | +}, |
| 41 | +plain: { |
| 42 | +raw: markRaw(plain), |
| 43 | +reactive: plain |
| 44 | +} |
| 45 | +}) |
| 46 | + |
| 47 | +expectType<Test<number>>(r.class.raw) |
| 48 | +// @ts-expect-error it should unwrap |
| 49 | +expectType<Test<number>>(r.class.reactive) |
| 50 | + |
| 51 | +expectType<Ref<number>>(r.plain.raw.ref) |
| 52 | +// @ts-expect-error it should unwrap |
| 53 | +expectType<Ref<number>>(r.plain.reactive.ref) |
| 54 | +}) |
| 55 | + |
| 56 | +describe('shallowReadonly ref unwrap',()=>{ |
| 57 | +constr=shallowReadonly({count: {n: ref(1)}}) |
| 58 | +// @ts-expect-error |
| 59 | +r.count=2 |
| 60 | +expectType<Ref>(r.count.n) |
| 61 | +r.count.n.value=123 |
| 62 | +}) |
| 63 | + |
| 64 | +// #3819 |
| 65 | +describe('should unwrap tuple correctly',()=>{ |
| 66 | +constreadonlyTuple=[ref(0)]asconst |
| 67 | +constreactiveReadonlyTuple=reactive(readonlyTuple) |
| 68 | +expectType<Ref<number>>(reactiveReadonlyTuple[0]) |
| 69 | + |
| 70 | +consttuple: [Ref<number>]=[ref(0)] |
| 71 | +constreactiveTuple=reactive(tuple) |
| 72 | +expectType<Ref<number>>(reactiveTuple[0]) |
| 73 | +}) |
0 commit comments