Skip to content

Add 35-mapping-modifiers #305

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

Merged
merged 3 commits into from
May 13, 2024

Conversation

someden
Copy link
Contributor

@someden someden commented May 5, 2024

No description provided.

@dzencot dzencot requested a review from bondiano May 7, 2024 09:06

Чтобы добавить или удалить эти модификаторы, можно использовать префиксы `+` или `-`. Если не использовать префикс, то подразумевается что модификатор будет добавлен, то есть по умолчанию префикс `+`.

Примеры использования модификаторов есть в Utility Types:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай подумаем над примером из реальной жизни

Подобным образом можно написать и тип, который делает все свойства типа изменяемыми, то есть удаляет атрибут `readonly`:

```typescript
type Mutable<T> = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай также покажем как используется

-readonly [P in keyof T]: T[P];
};
```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно добавить небольшой "рекап" - что мы изучили и как оно нам может пригодиться

const deepFreeze = <T extends object>(obj: T): DeepReadonly<T> => {
Object.freeze(obj);

Object.values(obj).forEach((value) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мы стараемся писать имутабельный код

@@ -0,0 +1,19 @@
// BEGIN
type DeepReadonly<T> = {
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а что делать с массивами?

@@ -0,0 +1,14 @@

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лишняя строчка

},
};

expect(deepFreeze(obj)).toEqual({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хорошо бы проверить что также сама логика валидная и мы не можем поменять свойства

@someden someden force-pushed the add-35-mapping-modifiers branch from 3058301 to b4e8abe Compare May 11, 2024 14:24
@bondiano bondiano merged commit 1932b28 into hexlet-basics:main May 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants