Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/bytebit-org/roblox-readonly
- Owner: Bytebit-Org
- License: mit
- Created: 2022-03-21T20:31:38.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-04-05T05:05:31.000Z (over 2 years ago)
- Last Synced: 2024-11-07T09:53:26.321Z (6 days ago)
- Topics: game-development, lua, luau, npm-package, roblox, roblox-ts
- Language: Python
- Homepage:
- Size: 97.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
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](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
}
}
```