Skip to content

Commit

Permalink
Rename asMutable to asWritable
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jul 26, 2024
1 parent 614d777 commit 03a66fd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {isDefined} from 'ts-extras';

**General**

- [`asMutable`](source/as-mutable.ts) - Cast the given value to be [`Mutable`](https://github.com/sindresorhus/type-fest/blob/main/source/mutable.d.ts).
- [`asWritable`](source/as-writable.ts) - Cast the given value to be [`Writable`](https://github.com/sindresorhus/type-fest/blob/main/source/writable.d.ts).

**Type guard**

Expand Down
19 changes: 0 additions & 19 deletions source/as-mutable.ts

This file was deleted.

19 changes: 19 additions & 0 deletions source/as-writable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {type Writable} from 'type-fest';

/**
Cast the given value to be [`Writable`](https://github.com/sindresorhus/type-fest/blob/main/source/writable.d.ts).
This is useful because of a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/45618#issuecomment-908072756).
@example
```
import {asWritable} from 'ts-extras';
const writableContext = asWritable((await import('x')).context);
```
@category General
*/
export function asWritable<T>(value: T): Writable<T> {
return value as any; // eslint-disable-line @typescript-eslint/no-unsafe-return
}
2 changes: 1 addition & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {arrayIncludes} from './array-includes.js';
export {asMutable} from './as-mutable.js';
export {asWritable} from './as-writable.js';
export {assertError} from './assert-error.js';
export {isDefined} from './is-defined.js';
export {isPresent} from './is-present.js';
Expand Down
17 changes: 0 additions & 17 deletions test/as-mutable.ts

This file was deleted.

17 changes: 17 additions & 0 deletions test/as-writable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import test from 'ava';
import {asWritable} from '../source/index.js';

test('asWritable()', t => {
type Fixture = {
readonly a: number;
};

const fixture: Fixture = {a: 1};

// @ts-expect-error
fixture.a = 2;

const writableFixture = asWritable(fixture);
writableFixture.a = 2;
t.is(writableFixture.a, 2);
});

0 comments on commit 03a66fd

Please sign in to comment.