In my quest to learning TypeScript, I am currently reading about Immutable Data with Readonly in TS. I know what the code below is supposed to do, which is return 0 and "1". I am confused tho as to what exactly type ReadonlyInterface<T> and function genericInterfaceToReadOnly<T> are suppose to be doing. Can somebody please explain?
interface OriginalInterface {
x: number;
y: string;
}
type ReadonlyInterface<T> = { readonly [P in keyof T]: T[P] };
function genericInterfaceToReadOnly<T>(o: T): ReadonlyInterface<T> {
return Object.freeze(o);
}
const original: OriginalInterface = { x: 0, y: "1" };
const originalReadonly = genericInterfaceToReadOnly(original);