-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: β add MarkWritable π * test: π§ͺ MarkWritable * docs: β add MarkWritable π * docs: π changeset * docs: π fix typo in README * docs: π update changeset
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ts-essentials": minor | ||
--- | ||
|
||
Add `MarkWritable` which unsets readonly for specified keys |
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 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 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,34 @@ | ||
import { AssertTrue as Assert, IsExact } from "conditional-type-checks"; | ||
import { MarkWritable, Writable, ReadonlyKeys, WritableKeys } from "../lib/types"; | ||
|
||
function testMarkWritable() { | ||
type Example = { | ||
readonly readonly1: Date; | ||
readonly readonly2: RegExp; | ||
required1: number; | ||
required2: string; | ||
optional1?: null; | ||
optional2?: boolean; | ||
}; | ||
|
||
type cases = [ | ||
Assert<IsExact<MarkWritable<Example, never>, Example>>, | ||
Assert<IsExact<MarkWritable<Example, WritableKeys<Example>>, Example>>, | ||
Assert<IsExact<MarkWritable<Example, ReadonlyKeys<Example>>, Writable<Example>>>, | ||
Assert< | ||
IsExact< | ||
MarkWritable<Example, "readonly1">, | ||
{ | ||
readonly1: Date; | ||
readonly readonly2: RegExp; | ||
required1: number; | ||
required2: string; | ||
optional1?: null; | ||
optional2?: boolean; | ||
} | ||
> | ||
>, | ||
// @ts-expect-error do NOT support union types | ||
MarkWritable<Example | { a: 1 }, "readonly1">, | ||
]; | ||
} |