Skip to content

Commit

Permalink
fix discriminated union not working in update operation
Browse files Browse the repository at this point in the history
  • Loading branch information
tylim88 committed Oct 18, 2023
1 parent e336967 commit dde700f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firelordjs",
"version": "2.6.27",
"version": "2.6.28",
"description": "🔥 High Precision Typescript Wrapper for Firestore Web, Providing Unparalleled Type Safe and Dev Experience",
"author": "tylim",
"license": "MIT",
Expand Down
53 changes: 53 additions & 0 deletions src/types/exactOptional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@ import { IsTrue, IsSame } from './utils'
import { ServerTimestamp } from './fieldValues'

describe('test exact optional', () => {
it('test discriminated union', () => {
IsTrue<
IsSame<
ExactOptional<
{ a: { b: 0; d: 1 } | { b: 1; c: 2 } },
{ a: { b: 0; d: 1 } },
false,
false,
true
>,
{
a?:
| { b?: 0; d?: 1 }
| HandleUnknownMember<
// TODO remove this extra type
{
b: 1
c: 2
},
{
b: 0
d: 1
}
>
}
>
>()
})

it('test union of primitive type with oject literal', () => {
IsTrue<
IsSame<
Expand Down Expand Up @@ -141,6 +170,30 @@ describe('test exact optional', () => {
})

describe('test RecursivelyReplaceDeleteFieldWithErrorMsg', () => {
it('test discriminated union', () => {
IsTrue<
IsSame<
RecursivelyReplaceDeleteFieldWithErrorMsg<
{ a: { b: 0; d: 1 } | { b: 1; c: 2 } },
{ a: { b: 0; d: 1 } }
>,
{
a:
| { b: 0; d: 1 }
| HandleUnknownMember<
{
b: 1
c: 2
},
{
b: 0
d: 1
}
>
}
>
>()
})
it('test union of primitive type with oject literal', () => {
IsTrue<
IsSame<
Expand Down
16 changes: 9 additions & 7 deletions src/types/exactOptional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ export type ExactOptional<
Merge extends boolean | string[], // this is for set merge operation only
NoFlatten extends boolean,
TopLevel extends boolean
> = Data extends (
NoFlatten extends true
? TopLevel extends true
? Record<string, never>
: never
: Record<string, never>
)
> = T extends never
? T
: Data extends (
NoFlatten extends true
? TopLevel extends true
? Record<string, never>
: never
: Record<string, never>
)
? ErrorEmptyUpdate | T
: keyof Data extends (string extends keyof T ? string | number : keyof T)
? {
Expand Down

0 comments on commit dde700f

Please sign in to comment.