Skip to content

Commit

Permalink
fix value of where clause top level field from discriminated unions b…
Browse files Browse the repository at this point in the history
…eing `never`
  • Loading branch information
tylim88 committed Mar 23, 2024
1 parent 47f1319 commit 39716a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 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.8.5",
"version": "2.8.6",
"description": "🔥 High Precision Typescript Wrapper for Firestore Web, Providing Unparalleled Type Safe and Dev Experience",
"author": "tylim",
"license": "MIT",
Expand Down
12 changes: 11 additions & 1 deletion src/tests/discriminatedUnion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {

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 },
| { x: { y: 1; z: 2; u: 3 } | { y: 'a'; w: 'b'; v: 'c' } | false }
| { c: false }
| { c: true; v: 0 },
'abc'
>

Expand All @@ -26,6 +28,10 @@ describe('test discrimination unions', () => {
// @ts-expect-error
updateDoc(docRef, { 'a.b': 2 })

updateDoc(docRef, { v: 0 })
// @ts-expect-error
updateDoc(docRef, { v: 1 })

const v = false as boolean

const x = v
Expand Down Expand Up @@ -79,6 +85,10 @@ describe('test discrimination unions', () => {
query(du.collection(), where('a.b', '==', 1))
// @ts-expect-error
query(du.collection(), where('a.b', '==', 2))

query(du.collection(), where('v', '==', 0))
// @ts-expect-error
query(du.collection(), where('v', '==', 1))
}
})
})
11 changes: 4 additions & 7 deletions src/types/objectFlatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ export type DeepKey<T, DontFlatMap extends string> = keyof T extends infer K
: never // impossible route
: never // impossible route

export type DeepValue<
T,
P extends string
> = P extends `${infer K}.${infer Rest}`
? T extends T
export type DeepValue<T, P extends string> = T extends T
? P extends `${infer K}.${infer Rest}`
? T[K & keyof T] extends infer S
? S extends S
? DeepValue<S, Rest>
: never // impossible route
: never // impossible route
: never // impossible route
: T[P & keyof T]
: T[P & keyof T]
: never // impossible route

export type ObjectFlatten<
Data,
Expand Down

0 comments on commit 39716a1

Please sign in to comment.