Mutable type
Removes readonly from the properties of a type, one level deep: a builder filling an object before handing it out as read-only.
ts
import type { Mutable } from 'utils';Signature
ts
export type Mutable<T> = { -readonly [K in keyof T]: T[K] };Parameters
| Name | Description |
|---|---|
T | The read-only type. |
Example
ts
const draft: Mutable<Point> = { x: 0, y: 0 };
draft.x = 10;Tests
Line coverage: 0 %.
- ✅ removes readonly
Source
src/types/mutable.ts (on GitHub)
Source code
ts
/**
* Removes `readonly` from the properties of a type, one level deep: a builder filling an object before
* handing it out as read-only.
*
* @template T - The read-only type.
* @example
* const draft: Mutable<Point> = { x: 0, y: 0 };
* draft.x = 10;
*/
export type Mutable<T> = { -readonly [K in keyof T]: T[K] };Test file
ts
import type { Mutable } from './mutable';
describe('Mutable', () => {
it('removes readonly', () => {
expectTypeOf<Mutable<{ readonly x: number }>>().toEqualTypeOf<{ x: number }>();
});
});Keywords: mutable, types, type