Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bytebit-org/roblox-readonly

Just a simple function that is really only useful in roblox-ts for forcing the value to be inferred as readonly.
https://github.com/bytebit-org/roblox-readonly

game-development lua luau npm-package roblox roblox-ts

Last synced: 6 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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](https://roblox-ts.com/) project as follows:
```
npm i @rbxts/readonly
```

## Documentation
Documentation can be found [here](https://github.com/Bytebit-Org/roblox-Readonly/tree/master/docs), is included in the TypeScript files directly, and was generated using [TypeDoc](https://typedoc.org/).

## 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.

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