Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions lessons/module2/1_TypescriptPart2/homework/easy1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Нужно заменить FIXME на тип который вычисляется на освове OrderState

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FIXME = any;
type UserOrderStates = Exclude<OrderState[], "buyingSupplies" | "producing">;

const orderStates = [
"initial",
Expand All @@ -15,8 +15,10 @@ const orderStates = [

type OrderState = typeof orderStates[number];

export const getUserOrderStates = (orderStates: OrderState[]): FIXME => {
const filteredStates = [] as FIXME;
export const getUserOrderStates = (
orderStates: OrderState[]
): UserOrderStates => {
const filteredStates = [] as UserOrderStates;
orderStates.forEach((element) => {
if (element !== "buyingSupplies" && element !== "producing") {
filteredStates.push(element);
Expand Down
4 changes: 2 additions & 2 deletions lessons/module2/1_TypescriptPart2/homework/easy2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Нужно заменить FIXME на тип который достанет из Order все возможные состояния (state)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FIXME = any;
type OrderState = { [P in keyof Order]: Order[P] }["state"];

Choose a reason for hiding this comment

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

ну явно же Order['stateэ], зачем городить велосипед


type Order =
| {
Expand Down Expand Up @@ -37,4 +37,4 @@ type Order =
fullfillmentDate: Date;
};

export const getOrderState = (order: Order): FIXME => order.state;
export const getOrderState = (order: Order): OrderState => order.state;
4 changes: 2 additions & 2 deletions lessons/module2/1_TypescriptPart2/homework/easy3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// Нужно заменить FIXME на соответствующий тип

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FIXME = any;
type FIXME<T, K extends number | symbol | string> = Omit<T, K>;

Choose a reason for hiding this comment

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

давай extend подправим


// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const omit = <T extends Record<any, any>, K extends keyof T>(
obj: T,
keyToOmit: K
): FIXME => {
): FIXME<T, K> => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { [keyToOmit]: _, ...withoutKey } = obj;
return withoutKey;
Expand Down
2 changes: 1 addition & 1 deletion lessons/module2/1_TypescriptPart2/homework/medium1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Нужно заменить FIXME на правильный тип вычисленный на основе Order

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FIXME = any;
type FIXME = Extract<Order, { state: "initial" } | { state: "inWork" }> | null;

type Order =
| {
Expand Down
7 changes: 3 additions & 4 deletions lessons/module2/1_TypescriptPart2/homework/medium2.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Задание второго уровня 2
// Есть функция которая достает из реакт компонента (любого, и Functional и Class) его defaultProps
// Нужно заменить FIXME на правильный тип

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FIXME = any;

import React from "react";
type FIXME<T> = T extends infer I ? I : never;
// Hint: infer
export const getDefaultProps = <T>(
component: React.ComponentType<T>
): FIXME => {
): FIXME<T> => {
return component.defaultProps;
};
10 changes: 6 additions & 4 deletions lessons/module2/1_TypescriptPart2/homework/medium3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FIXME = any;
type FIXME = Exclude<OrderState, "buyingSupplies" | "producing">;

const orderStates = [
"initial",
Expand All @@ -10,9 +10,11 @@ const orderStates = [
] as const;

type OrderState = typeof orderStates[number];

// Hint: type guards
export const getUserOrderStates = (orderStates: OrderState[]): FIXME =>
export const getUserOrderStates = (
orderStates: readonly OrderState[]
): FIXME[] =>
orderStates.filter(
(state) => state !== "buyingSupplies" && state !== "producing"
(state): state is FIXME =>
state !== "buyingSupplies" && state !== "producing"
);