-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
614d777
commit 03a66fd
Showing
6 changed files
with
38 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |