@rbxts/readonly
v1.0.1
Published
Just a simple function that is really only useful in roblox-ts for forcing the value to be inferred as readonly.
Downloads
3
Readme
Readonly
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.
Installation
roblox-ts
Simply install to your roblox-ts project as follows:
npm i @rbxts/readonly
Documentation
Documentation can be found here, is included in the TypeScript files directly, and was generated using TypeDoc.
Example
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
}
}