Skip to main content

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)ReadWriteCompare
numbernumbernumber | Incrementnumber
numeric literalnumeric literalnumeric literalnumeric literal
stringstringstringstring
string literalstring literalstring literalstring literal
nullnullnullnull
ServerTimestampnumberServerTimestampnumber
Record<string, T>Record<string, converted<T>>Record<string, converted<T>>invalid
Removablenull | undefinednevernever
PossiblyReadAsUndefinedRecord\<${number}, converted\<T>>Record\<${number}, converted\<T>> | converted\<T>[]invalid
PushAbleOnlyRecord<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 is 1 | 100 | 1000 then we should not be able to increment it from 1 to 2.

  • FireSageJS forbids you from writing number into ServerTimestamp, because some date time has to be server timestamp, such as createdAt and updatedAt. However if this is your intention, you can by union ServerTimestamp with number.

  • We can always compare number to ServerTimestamp.