Skip to content

Commit efd99bd

Browse files
committed
update test
1 parent d8855bf commit efd99bd

File tree

1 file changed

+56
-54
lines changed

1 file changed

+56
-54
lines changed

src/tests/discriminatedUnion.test.ts

+56-54
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,65 @@
11
import { MetaTypeCreator, getFirelord, getFirestore, updateDoc } from '../index'
22

33
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 } })
4517

46-
const data = {
47-
x: v
18+
const v = false as boolean
19+
20+
const x = v
4821
? {
49-
y: 1,
50-
z: 2,
51-
u: 3,
22+
y: 1 as const,
5223
}
5324
: {
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)
5863
}
59-
// should be error because no const assertion but ok
60-
// @ts-expect-error
61-
updateDoc(docRef, data)
62-
}
64+
})
6365
})

0 commit comments

Comments
 (0)