-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,65 @@ | ||
import { MetaTypeCreator, getFirelord, getFirestore, updateDoc } from '../index' | ||
|
||
describe('test update discrimination unions', () => { | ||
;() => { | ||
type DU = MetaTypeCreator< | ||
| { a: { b: 1; c: 2 } | { b: 'a'; d: 'b' } } | ||
| { x: { y: 1; z: 2; u: 3 } | { y: 'a'; w: 'b'; v: 'c' } | false }, | ||
'abc' | ||
> | ||
|
||
const du = getFirelord<DU>(getFirestore(), 'abc') | ||
|
||
const docRef = du.doc('123') | ||
|
||
updateDoc(docRef, { a: { b: 1 } }) | ||
|
||
const v = false as boolean | ||
|
||
const x = v | ||
? { | ||
y: 1 as const, | ||
} | ||
: { | ||
w: 'b' as const, | ||
} | ||
|
||
// ok as expected | ||
updateDoc(docRef, { | ||
x, | ||
}) | ||
|
||
// should be ok but error | ||
// this error is unrelated to const assertion because of const modifier on type parameters | ||
updateDoc(docRef, { | ||
x: v | ||
? { | ||
y: 1, | ||
z: 2, | ||
} | ||
: { | ||
w: 'b', | ||
v: 'c', | ||
}, | ||
}) | ||
describe('test discrimination unions', () => { | ||
it('test update', () => { | ||
;() => { | ||
type DU = MetaTypeCreator< | ||
| { a: { b: 1; c: 2 } | { b: 'a'; d: 'b' } } | ||
| { x: { y: 1; z: 2; u: 3 } | { y: 'a'; w: 'b'; v: 'c' } | false }, | ||
'abc' | ||
> | ||
|
||
const du = getFirelord<DU>(getFirestore(), 'abc') | ||
|
||
const docRef = du.doc('123') | ||
|
||
updateDoc(docRef, { a: { b: 1 } }) | ||
|
||
const data = { | ||
x: v | ||
const v = false as boolean | ||
|
||
const x = v | ||
? { | ||
y: 1, | ||
z: 2, | ||
u: 3, | ||
y: 1 as const, | ||
} | ||
: { | ||
y: 'a', | ||
w: 'b', | ||
v: 'c', | ||
}, | ||
w: 'b' as const, | ||
} | ||
|
||
// ok as expected | ||
updateDoc(docRef, { | ||
x, | ||
}) | ||
|
||
// should be ok but error | ||
// this error is unrelated to const assertion because of const modifier on type parameters | ||
updateDoc(docRef, { | ||
x: v | ||
? { | ||
y: 1, | ||
z: 2, | ||
} | ||
: { | ||
w: 'b', | ||
v: 'c', | ||
}, | ||
}) | ||
|
||
const data = { | ||
x: v | ||
? { | ||
y: 1, | ||
z: 2, | ||
u: 3, | ||
} | ||
: { | ||
y: 'a', | ||
w: 'b', | ||
v: 'c', | ||
}, | ||
} | ||
// should be error because no const assertion but ok | ||
// @ts-expect-error | ||
updateDoc(docRef, data) | ||
} | ||
// should be error because no const assertion but ok | ||
// @ts-expect-error | ||
updateDoc(docRef, data) | ||
} | ||
}) | ||
}) |