Readonly is just a simple function that is really only useful in roblox-ts for forcing the value to be inferred as readonly. Note that it is not a deep readonly - nested objects will still be just as mutable as they were without this function.
Simply install to your roblox-ts project as follows:
npm i @rbxts/readonly
Documentation can be found here, is included in the TypeScript files directly, and was generated using TypeDoc.
Here's a simple example of just getting a reference to an object and forcing the reference to be marked as readonly. Note that the nested value is still mutable.
import { readonly } from "@rbxts/readonly";
type SomeValue = {
message: string,
someOtherValue: SomeValue,
};
declare function getSomeValue(): SomeValue;
export class Foo {
public bar() {
const value = readonly(getSomeValue());
value.someOtherValue.message = "can mutate this"; // perfectly fine
value.message = "can't mutate this"; // TypeScript error
// more logic
}
}