3 ms·
Notion would be a useful at-scale codebase for a case-study: - How often are you forced to interact with JS objects over ECMA6 Maps? - How often are you not f
by derefr 3y ago
Notion would be a useful at-scale codebase for a case-study:
- How often are you forced to interact with JS objects over ECMA6 Maps?
- How often are you not forced to use JS objects over ECMA6 Maps, but are using them anyway?
- jitl 3y agoES6 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.