https://github.com/narumincho/readonly
TypeScript readonly type
https://github.com/narumincho/readonly
deno immutable typescript
Last synced: 4 months ago
JSON representation
TypeScript readonly type
- Host: GitHub
- URL: https://github.com/narumincho/readonly
- Owner: narumincho
- License: mit
- Created: 2024-07-13T01:03:44.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-11T01:02:33.000Z (over 1 year ago)
- Last Synced: 2025-09-03T08:53:27.691Z (10 months ago)
- Topics: deno, immutable, typescript
- Language: TypeScript
- Homepage: https://jsr.io/@narumincho/readonly
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @narumincho/readonly
https://jsr.io/@narumincho/readonly
TypeScript readonly type
- ReadonlyURL
- ReadonlyURLSearchParams
- ReadonlyUint8Array
## Example
```ts
const url = new URL("https://example.com");
func(url);
console.log(url); // https://example.com/aaa
const func = (url: URL): void => {
url.pathname = "/aaa";
};
```
```ts
import type { ReadonlyURL } from "jsr:@narumincho/readonly";
const url = new URL("https://example.com");
func(url);
console.log(url);
const func = (url: ReadonlyURL): void => {
url.pathname = "/aaa"; // Cannot assign to 'pathname' because it is a read-only property.
};
```
With `jsr:@narumincho/readonly`, URLs can be guaranteed not to be overwritten