Skip to content

Just a simple function that is really only useful in roblox-ts for forcing the value to be inferred as readonly.

License

Notifications You must be signed in to change notification settings

Bytebit-Org/roblox-Readonly

Repository files navigation

Readonly

CI status PRs Welcome License: MIT Discord server

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
  }
}

About

Just a simple function that is really only useful in roblox-ts for forcing the value to be inferred as readonly.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published