Can you explain the distinction between type Record<string, unkown> and type object?
Create a generic DeepReadonly<T>
which ensures that every parameter of an object - and its nested objects recursively - is readonly.
Here's the type I came up with:
type DeepReadonly<T> = T extends object ? {readonly:[K in keyof T]:DeepReadonly<T[K]>}:T
However, it seems to have a flaw.
When I replaced object
with Record<string,unkown>
, the 'DeepReadonly' function worked correctly.
So, what is the difference?
Could it be that object
allows for an empty declaration, whereas Record<string,unkown>
requires specific key-value pairs?