Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
tylim88 committed Oct 19, 2023
1 parent 42a1163 commit 89d244d
Showing 1 changed file with 57 additions and 55 deletions.
112 changes: 57 additions & 55 deletions src/tests/discriminatedUnion.test.ts
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)
}
})
})

0 comments on commit 89d244d

Please sign in to comment.