Skip to content

Commit d8855bf

Browse files
committed
update test
1 parent 6d358c6 commit d8855bf

File tree

1 file changed

+49
-47
lines changed

1 file changed

+49
-47
lines changed

src/tests/discriminatedUnion.test.ts

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

33
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+
>
910

10-
const du = getFirelord<DU>(getFirestore(), 'abc')
11+
const du = getFirelord<DU>(getFirestore(), 'abc')
1112

12-
const docRef = du.doc('123')
13+
const docRef = du.doc('123')
1314

14-
updateDoc(docRef, { a: { b: 1 } })
15+
updateDoc(docRef, { a: { b: 1 } })
1516

16-
const v = false as boolean
17+
const v = false as boolean
1718

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
3520
? {
36-
y: 1,
37-
z: 2,
21+
y: 1 as const,
3822
}
3923
: {
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,
5125
}
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)
5762
}
58-
// should be error because no const assertion but ok
59-
// @ts-expect-error
60-
updateDoc(docRef, data)
6163
})

0 commit comments

Comments
 (0)