Type alias ReadOnlyRecord<Key, Value>

ReadOnlyRecord<Key, Value>: ReadOnly<Record<Key, Value>>

Read-only record.


There's already a native Readonly and Record type, but this type has default type parameters to make it easier to use when the type of a record is unknown, plus it recursively makes all the values in the record read-only.


const record: ReadOnlyRecord<string, Array<number>> = {
"🟢": [1, 2, 3],
"🟩": [4, 5, 6],
record["🟢"][0] = 7; // Error



Type Parameters

  • Key extends PropertyKey = PropertyKey

    Type of the keys in the record.

  • Value = unknown

    Type of the values in the record.