🔥High Precision Typescript Wrapper for Firestore Web, Providing Unparalleled Type Safe and Dev Experience
MIT License
Firelord React Native
Firelord Admin
Firelord Web
Published by tylim88 6 months ago
remove document path trailing slash, it used to be 'a/b/c/d/', now it is 'a/b/c'
the trailing slash apparently causes random fail in tests(?)
Published by tylim88 7 months ago
fix nested object in mapped type is not partial in update
type DU = MetaTypeCreator<Record<string, { k: Record<`${1 | 2 | 3}`, number> }>, 'abc'>
const du = getFirelord<DU>(getFirestore(), 'abc')
const docRef = du.doc('123')
updateDoc(docRef, { x: { k: { '1': 1 } } }) // unexpected error requires all properties to present, now is fixed
Published by tylim88 7 months ago
fix value of where
clause top level field from discriminated unions being never
import {
MetaTypeCreator,
query,
where,
} from 'firelordjs'
type DU = MetaTypeCreator<
{ c: false } | { c: true; v: 0 },
'abc'
>
const du = getFirelord<DU>(getFirestore(), 'abc')
query(du.collection(), where('v', '==', 0)) //should be ok but error
Published by tylim88 7 months ago
export ArrayUnionOrRemove
type
fix discriminated union value is inferred as never
in where
clause
import {
MetaTypeCreator,
query,
where,
} from 'firelordjs'
type DU = MetaTypeCreator<
{ a: { b: 1; c: 2 } | { b: 'a'; d: 'b' } },
'abc'
>
const du = getFirelord<DU>(getFirestore(), 'abc')
query(du.collection(), where('a.b', '==', 2)) // previously no error but is expected to error
Published by tylim88 8 months ago
solved where
clause unable to get all keys of object unions type
Published by tylim88 8 months ago
now require typescript 5.4.2 and above
also please change your vscode TS version to 5.4.2, guide: https://firelordjs.com/change_ts_version
Published by tylim88 12 months ago
string
given this type:
{
a: Record<string,{ b: number, c: { d: string } }>
}
previously firelord generates the flattened path that look like:
{
a: Record<string,{ b: number, c: { d: string } }>
[x : `a.${string}`]: { b: number, c: { d: string } }
[x : `a.${string}.b`]: number
[x : `a.${string}.c`]: { d: string }
[x : `a.${string}.c.d`]: string
}
the problem is: a.${string}.b
, a.${string}.c
and a.${string}.c.d
will collapsed into a.${string}
to address this issue, firelord now generates:
{
a: Record<string, { b: number, c: { d: string }, `c.d`: string }>
}
firelord will not attempt to flatten mapped type, but will still continue to flatten any nested object literal type, in this case it is the c.d
affected operation: all update operations
JSON type is now available by accessing meta type instead: Example['readJSON']
Published by tylim88 about 1 year ago
solved discriminated union not working correctly when using it with ternary
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')
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',
},
})
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
updateDoc(docRef, data)
2.6.29 fixed these issues
Published by tylim88 about 1 year ago
fix discriminated unions not working in update operations (result in false error)
Published by tylim88 about 1 year ago
set
operation throw false type error when working with mapped type where the key
type is string
example meta type
type A = MetatypeCreator<{
a: Record<string, number>
},'id'>
this will throw type error even though it should be correct
const b:string = "zzz"
setDoc(ref, { a: { [b]: "yyy" } })
this is because keyof type { [x: string]: unknown }
is string | number
while keyof Record<string, number>
is string
2.6.27 fixed this issue
Published by tylim88 about 1 year ago
fix update operation missing autocomplete if the data is an empty object
Published by tylim88 about 1 year ago
add toTimestamp
to convert JSONTimeStamp to Firestore Timestamp:
import { toTimestamp } from 'firelordjs'
const firestoreTimestamp = toTimestamp(someJSONTimestamp)
https://firelordjs.com/highlights/transformative_types#json-types
Published by tylim88 about 1 year ago
updateDocNoFlatten
to receive empty object as argument on nested levelupdateDocNoFlatten(docRef, { } ) // this will still throw type error
updateDocNoFlatten(docRef, { a: { } } ) // this will not throw type error. It will delete all members of object 'a' (default behavior of firestore update operation)
The type of dynamic object key is not working properly if the type is mapped type, e.g.
updateDoc(ref, { a:{ [b]:1 } })
where the type is{ a:Record<string,number> }
.
Published by tylim88 about 1 year ago
fix updateDoc does not error on nested unknown key
example, given this type {a: { b:2 } }
updateDoc(ref, {a: { c:2 }}) // will not error, it is wrongly expecting {c?: unknown}, this is a false positive
2.6.15 fixed this issue
this is a very old bug
Published by tylim88 about 1 year ago
fix updateDoc object literal types are not optional if union with non-object literal type
example, given this type {a: false | {b:2, c:3} }
updateDoc(ref, {a: { b:2 }}) // will error, it is wrongly expecting {b:2, c:3}, this is a false error
2.6.13 fixed this issue
Published by tylim88 about 1 year ago
expand json type, example
old:
new:
Published by tylim88 about 1 year ago
rename Serial types to JSON types for easier understanding https://firelordjs.com/highlights/transformative_types/#json-types
Published by tylim88 about 1 year ago
Introduce serial types
Published by tylim88 about 1 year ago
void | Promise<void>
because popular eslint rule no-misused-promises throw error if you try to use async callback