diff --git a/lessons/module2/1_TypescriptPart2/homework/easy1.ts b/lessons/module2/1_TypescriptPart2/homework/easy1.ts index 938773d6..2fdeaa2f 100644 --- a/lessons/module2/1_TypescriptPart2/homework/easy1.ts +++ b/lessons/module2/1_TypescriptPart2/homework/easy1.ts @@ -3,7 +3,7 @@ // Нужно заменить FIXME на тип который вычисляется на освове OrderState // eslint-disable-next-line @typescript-eslint/no-explicit-any -type FIXME = any; +type UserOrderStates = Exclude; const orderStates = [ "initial", @@ -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); diff --git a/lessons/module2/1_TypescriptPart2/homework/easy2.ts b/lessons/module2/1_TypescriptPart2/homework/easy2.ts index ecf004fe..9c3c56cc 100644 --- a/lessons/module2/1_TypescriptPart2/homework/easy2.ts +++ b/lessons/module2/1_TypescriptPart2/homework/easy2.ts @@ -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"]; type Order = | { @@ -37,4 +37,4 @@ type Order = fullfillmentDate: Date; }; -export const getOrderState = (order: Order): FIXME => order.state; +export const getOrderState = (order: Order): OrderState => order.state; diff --git a/lessons/module2/1_TypescriptPart2/homework/easy3.ts b/lessons/module2/1_TypescriptPart2/homework/easy3.ts index 348b8146..56823c5b 100644 --- a/lessons/module2/1_TypescriptPart2/homework/easy3.ts +++ b/lessons/module2/1_TypescriptPart2/homework/easy3.ts @@ -3,13 +3,13 @@ // Нужно заменить FIXME на соответствующий тип // eslint-disable-next-line @typescript-eslint/no-explicit-any -type FIXME = any; +type FIXME = Omit; // eslint-disable-next-line @typescript-eslint/no-explicit-any export const omit = , K extends keyof T>( obj: T, keyToOmit: K -): FIXME => { +): FIXME => { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { [keyToOmit]: _, ...withoutKey } = obj; return withoutKey; diff --git a/lessons/module2/1_TypescriptPart2/homework/medium1.ts b/lessons/module2/1_TypescriptPart2/homework/medium1.ts index 15b76fbe..66fb9de3 100644 --- a/lessons/module2/1_TypescriptPart2/homework/medium1.ts +++ b/lessons/module2/1_TypescriptPart2/homework/medium1.ts @@ -5,7 +5,7 @@ // Нужно заменить FIXME на правильный тип вычисленный на основе Order // eslint-disable-next-line @typescript-eslint/no-explicit-any -type FIXME = any; +type FIXME = Extract | null; type Order = | { diff --git a/lessons/module2/1_TypescriptPart2/homework/medium2.ts b/lessons/module2/1_TypescriptPart2/homework/medium2.ts index 1ec88f5f..9164a7f4 100644 --- a/lessons/module2/1_TypescriptPart2/homework/medium2.ts +++ b/lessons/module2/1_TypescriptPart2/homework/medium2.ts @@ -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 extends infer I ? I : never; // Hint: infer export const getDefaultProps = ( component: React.ComponentType -): FIXME => { +): FIXME => { return component.defaultProps; }; diff --git a/lessons/module2/1_TypescriptPart2/homework/medium3.ts b/lessons/module2/1_TypescriptPart2/homework/medium3.ts index 71b9f1e4..98898bde 100644 --- a/lessons/module2/1_TypescriptPart2/homework/medium3.ts +++ b/lessons/module2/1_TypescriptPart2/homework/medium3.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any -type FIXME = any; +type FIXME = Exclude; const orderStates = [ "initial", @@ -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" );