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