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*,onValueand etc. - Write type for
set,updateand 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 literaltype, eg: if the type is1 | 100 | 1000then we should not be able to increment it from1to2.FireSageJS forbids you from writing
numberintoServerTimestamp, because some date time has to be server timestamp, such ascreatedAtandupdatedAt. However if this is your intention, you can by unionServerTimestampwithnumber.We can always compare
numbertoServerTimestamp.