Type Conversion
This page discusses how FireSageJS transforms your types for various uses internally.
Type transformation is needed because read, write and compare operation require or output different data types.
Conversion Table
Base(T) | Read | Write | Compare |
---|---|---|---|
number | number | number | Increment | number |
numeric literal | numeric literal | numeric literal | numeric literal |
string | string | string | string |
string literal | string literal | string literal | string literal |
null | null | null | null |
ServerTimestamp | number | ServerTimestamp | number |
Record<string, T> | Record<string, converted<T>> | Record<string, converted<T>> | invalid |
Removable | null | undefined | never | never |
PossiblyReadAsUndefined | Record\<${number} , converted\<T>> | Record\<${number} , converted\<T>> | converted\<T>[] | invalid |
PushAbleOnly | Record<string, converted<T>> | Record<string, converted<T>> | invalid |
NumericKeyRecord<T> | Record<string, converted<T>> | Record<string, converted<T>> | invalid |
Internally, FireSageJS converts base type into 3 main types for different purpose:
- Read type for
get
,onChild*
,onValue
and etc. - Write type for
set
,update
and etc. - Compare type for cursors,
orderBy*
and etc.
The main types are further transformed for even more specific use cases internally.
Key Points:
FireSageJS forbids you from increment
numeric literal
type, eg: if the type is1 | 100 | 1000
then we should not be able to increment it from1
to2
.FireSageJS forbids you from writing
number
intoServerTimestamp
, because some date time has to be server timestamp, such ascreatedAt
andupdatedAt
. However if this is your intention, you can by unionServerTimestamp
withnumber
.We can always compare
number
toServerTimestamp
.