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.
Readonly
Record
unknown
const record: ReadOnlyRecord<string, Array<number>> = { "🟢": [1, 2, 3], "🟩": [4, 5, 6],};record["🟢"][0] = 7; // Error Copy
const record: ReadOnlyRecord<string, Array<number>> = { "🟢": [1, 2, 3], "🟩": [4, 5, 6],};record["🟢"][0] = 7; // Error
ReadOnly
Type of the keys in the record.
Type of the values in the record.
Read-only record.
Remarks
There's already a native
Readonly
andRecord
type, but this type has default type parameters to make it easier to use when the type of a record isunknown
, plus it recursively makes all the values in the record read-only.Example
See
ReadOnly