|
1 | 1 | import { MetaTypeCreator, getFirelord, getFirestore, updateDoc } from '../index'
|
2 | 2 |
|
3 | 3 | describe('test update discrimination unions', () => {
|
4 |
| - ;() => { |
5 |
| - type DU = MetaTypeCreator< |
6 |
| - | { a: { b: 1; c: 2 } | { b: 'a'; d: 'b' } } |
7 |
| - | { x: { y: 1; z: 2; u: 3 } | { y: 'a'; w: 'b'; v: 'c' } | false }, |
8 |
| - 'abc' |
9 |
| - > |
10 |
| - |
11 |
| - const du = getFirelord<DU>(getFirestore(), 'abc') |
12 |
| - |
13 |
| - const docRef = du.doc('123') |
14 |
| - |
15 |
| - updateDoc(docRef, { a: { b: 1 } }) |
16 |
| - |
17 |
| - const v = false as boolean |
18 |
| - |
19 |
| - const x = v |
20 |
| - ? { |
21 |
| - y: 1 as const, |
22 |
| - } |
23 |
| - : { |
24 |
| - w: 'b' as const, |
25 |
| - } |
26 |
| - |
27 |
| - // ok as expected |
28 |
| - updateDoc(docRef, { |
29 |
| - x, |
30 |
| - }) |
31 |
| - |
32 |
| - // should be ok but error |
33 |
| - // this error is unrelated to const assertion because of const modifier on type parameters |
34 |
| - updateDoc(docRef, { |
35 |
| - x: v |
36 |
| - ? { |
37 |
| - y: 1, |
38 |
| - z: 2, |
39 |
| - } |
40 |
| - : { |
41 |
| - w: 'b', |
42 |
| - v: 'c', |
43 |
| - }, |
44 |
| - }) |
| 4 | + it('test update', () => { |
| 5 | + ;() => { |
| 6 | + type DU = MetaTypeCreator< |
| 7 | + | { a: { b: 1; c: 2 } | { b: 'a'; d: 'b' } } |
| 8 | + | { x: { y: 1; z: 2; u: 3 } | { y: 'a'; w: 'b'; v: 'c' } | false }, |
| 9 | + 'abc' |
| 10 | + > |
| 11 | + |
| 12 | + const du = getFirelord<DU>(getFirestore(), 'abc') |
| 13 | + |
| 14 | + const docRef = du.doc('123') |
| 15 | + |
| 16 | + updateDoc(docRef, { a: { b: 1 } }) |
45 | 17 |
|
46 |
| - const data = { |
47 |
| - x: v |
| 18 | + const v = false as boolean |
| 19 | + |
| 20 | + const x = v |
48 | 21 | ? {
|
49 |
| - y: 1, |
50 |
| - z: 2, |
51 |
| - u: 3, |
| 22 | + y: 1 as const, |
52 | 23 | }
|
53 | 24 | : {
|
54 |
| - y: 'a', |
55 |
| - w: 'b', |
56 |
| - v: 'c', |
57 |
| - }, |
| 25 | + w: 'b' as const, |
| 26 | + } |
| 27 | + |
| 28 | + // ok as expected |
| 29 | + updateDoc(docRef, { |
| 30 | + x, |
| 31 | + }) |
| 32 | + |
| 33 | + // should be ok but error |
| 34 | + // this error is unrelated to const assertion because of const modifier on type parameters |
| 35 | + updateDoc(docRef, { |
| 36 | + x: v |
| 37 | + ? { |
| 38 | + y: 1, |
| 39 | + z: 2, |
| 40 | + } |
| 41 | + : { |
| 42 | + w: 'b', |
| 43 | + v: 'c', |
| 44 | + }, |
| 45 | + }) |
| 46 | + |
| 47 | + const data = { |
| 48 | + x: v |
| 49 | + ? { |
| 50 | + y: 1, |
| 51 | + z: 2, |
| 52 | + u: 3, |
| 53 | + } |
| 54 | + : { |
| 55 | + y: 'a', |
| 56 | + w: 'b', |
| 57 | + v: 'c', |
| 58 | + }, |
| 59 | + } |
| 60 | + // should be error because no const assertion but ok |
| 61 | + // @ts-expect-error |
| 62 | + updateDoc(docRef, data) |
58 | 63 | }
|
59 |
| - // should be error because no const assertion but ok |
60 |
| - // @ts-expect-error |
61 |
| - updateDoc(docRef, data) |
62 |
| - } |
| 64 | + }) |
63 | 65 | })
|
0 commit comments