From ebcc4517ee1144ceed79c56761c5b728284d3a24 Mon Sep 17 00:00:00 2001 From: Radamir Date: Sun, 29 Jan 2023 19:09:54 +0300 Subject: [PATCH] homework --- .../1_TypescriptPart2/homework/easy1.ts | 2 +- .../1_TypescriptPart2/homework/easy2.ts | 2 +- .../1_TypescriptPart2/homework/easy3.ts | 10 ++- .../1_TypescriptPart2/homework/medium1.ts | 78 +++++++++++-------- 4 files changed, 56 insertions(+), 36 deletions(-) diff --git a/lessons/module2/1_TypescriptPart2/homework/easy1.ts b/lessons/module2/1_TypescriptPart2/homework/easy1.ts index 938773d6..79b6967c 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 FIXME = Array>; const orderStates = [ "initial", diff --git a/lessons/module2/1_TypescriptPart2/homework/easy2.ts b/lessons/module2/1_TypescriptPart2/homework/easy2.ts index ecf004fe..47f5fa7b 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 FIXME = Order["state"]; type Order = | { diff --git a/lessons/module2/1_TypescriptPart2/homework/easy3.ts b/lessons/module2/1_TypescriptPart2/homework/easy3.ts index 348b8146..f68224e8 100644 --- a/lessons/module2/1_TypescriptPart2/homework/easy3.ts +++ b/lessons/module2/1_TypescriptPart2/homework/easy3.ts @@ -3,13 +3,19 @@ // Нужно заменить FIXME на соответствующий тип // eslint-disable-next-line @typescript-eslint/no-explicit-any -type FIXME = any; +type FIXME, K extends keyof T> = Pick< + T, + Exclude +>; + +//или второе решение +type FIXME2, K extends keyof T> = Omit; // eslint-disable-next-line @typescript-eslint/no-explicit-any export const omit = , K extends keyof T>( obj: T, keyToOmit: K -): FIXME => { +): FIXME2 => { // 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..ffc08962 100644 --- a/lessons/module2/1_TypescriptPart2/homework/medium1.ts +++ b/lessons/module2/1_TypescriptPart2/homework/medium1.ts @@ -7,39 +7,53 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any type FIXME = any; +type InitialOrder = { + state: "initial"; + sum: number; +}; + +type InWorkOrder = { + state: "inWork"; + sum: number; + workerId: number; +}; + +type BuyingSuppliesOrder = { + state: "buyingSupplies"; + sum: number; + workerId: number; + suppliesSum: number; +}; + +type ProducingOrder = { + state: "producing"; + sum: number; + workerId: number; + suppliesSum: number; + produceEstimate: Date; +}; + +type FullfilledOrder = { + state: "fullfilled"; + sum: number; + workerId: number; + suppliesSum: number; + produceEstimate: Date; + fullfillmentDate: Date; +}; + type Order = - | { - state: "initial"; - sum: number; - } - | { - state: "inWork"; - sum: number; - workerId: number; - } - | { - state: "buyingSupplies"; - sum: number; - workerId: number; - suppliesSum: number; - } - | { - state: "producing"; - sum: number; - workerId: number; - suppliesSum: number; - produceEstimate: Date; - } - | { - state: "fullfilled"; - sum: number; - workerId: number; - suppliesSum: number; - produceEstimate: Date; - fullfillmentDate: Date; - }; - -export const filterOnlyInitialAndInWorkOrder = (order: Order): FIXME => { + | InitialOrder + | InWorkOrder + | BuyingSuppliesOrder + | ProducingOrder + | FullfilledOrder; + +type InitialOrInWorkOrder = InitialOrder | InWorkOrder; + +export const filterOnlyInitialAndInWorkOrder = ( + order: Order +): InitialOrInWorkOrder | null => { if (order.state === "initial" || order.state === "inWork") { return order; }