Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PickWritable): Add PickWritable #72

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs(PickWritable): Add PickWritable docs
  • Loading branch information
haejunejung committed Sep 16, 2024
commit f8903e0ab4411418ecf5a9599721c350d5aed1a4
4 changes: 4 additions & 0 deletions docs/.vitepress/ko.mts
Original file line number Diff line number Diff line change
@@ -117,6 +117,10 @@ export default defineConfig({
text: 'PickRequired',
link: '/ko/reference/utilities/PickRequired',
},
{
text: 'PickWritable',
link: '/ko/reference/utilities/PickWritable',
},
{
text: 'Simplify',
link: '/ko/reference/utilities/Simplify',
22 changes: 22 additions & 0 deletions docs/ko/reference/utilities/PickWritable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# PickWritable<T, K>

## 개요

선택된 키를 수정가능하도록 만들고 나머지 타입은 변경되지 않은 상태를 유지하는 새로운 타입을 생성해요.

## 문법

```ts
type PickWritable<T, K extends keyof T> = Simplify<
Omit<T, K> & { -readonly [P in K]: T[P] }
>;
```

## 예제

```ts
type T0 = { readonly a: string; readonly b: number; readonly c: boolean };
type E0 = PickWritable<T0, 'a'>; // { a: string, readonly b: number, readonly c: boolean}
type E1 = PickWritable<T0, 'a' | 'b'>; // { a: string, b: number, readonly c: boolean }
type E2 = PickWritable<T0, 'a' | 'b'>; // { a: string, b: number, c: boolean }
```
22 changes: 22 additions & 0 deletions docs/reference/utilities/PickWritable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# PickWritable<T, K>

## Overview

Creates a new type where the specified keys are made writable, while keeping the rest of the type remain unchanged.

## Syntax

```ts
type PickWritable<T, K extends keyof T> = Simplify<
Omit<T, K> & { -readonly [P in K]: T[P] }
>;
```

## Example

```ts
type T0 = { readonly a: string; readonly b: number; readonly c: boolean };
type E0 = PickWritable<T0, 'a'>; // { a: string, readonly b: number, readonly c: boolean}
type E1 = PickWritable<T0, 'a' | 'b'>; // { a: string, b: number, readonly c: boolean }
type E2 = PickWritable<T0, 'a' | 'b'>; // { a: string, b: number, c: boolean }
```