4 ms·
ES6 maps don't work well with mapped types where we encode a type-level relationship between a key and a value depending on the key type: type BlockRendere
by jitl 3y ago
ES6 maps don't work well with mapped types where we encode a type-level relationship between a key and a value depending on the key type:
type BlockRenderers<Out> = {
[key in keyof BlockValues]: (
args: BlockRenderArgs<Out, BlockValues[key]>
) => Out | undefined
}
or something like:
type Table = 'block' /* | ... ~70 other table names */
type ID<T extends Table> = `${T}:${UUID}`
type TableToRow = {
block: BlockValue
// ... ~70 other table schemas
}
type RowsById = { [T in Table as ID<T>]: TableToRow[T] }
Maps are also annoying to persist compared Record<K, V> types which just work with JSON. The majority of our code is oriented around JSON-serializable discriminated union types. In my benchmarking, transcoding to/from Map<K, V> to Record<K, V> doesn't seem worth the effort.
So, we Map for in-memory only data organization and some framework stuff but most engineers tend to interact much more with persisted data and thus Record types.