From 3d6be87225d343c90bfdf8636b6f572b2343e97d Mon Sep 17 00:00:00 2001 From: "d.golovko" Date: Tue, 11 Apr 2023 23:48:15 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D1=8F?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lessons/module2/1_TypescriptPart2/homework/easy1.ts | 6 +++--- lessons/module2/1_TypescriptPart2/homework/easy2.ts | 4 ++-- lessons/module2/1_TypescriptPart2/homework/easy3.ts | 6 +++--- lessons/module2/1_TypescriptPart2/homework/medium1.ts | 2 +- lessons/module2/1_TypescriptPart2/homework/medium2.ts | 11 +++++------ lessons/module2/1_TypescriptPart2/homework/medium3.ts | 9 ++++----- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lessons/module2/1_TypescriptPart2/homework/easy1.ts b/lessons/module2/1_TypescriptPart2/homework/easy1.ts index 938773d6..00f6be10 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,8 @@ 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..07763fcc 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..527f0a8b 100644 --- a/lessons/module2/1_TypescriptPart2/homework/easy3.ts +++ b/lessons/module2/1_TypescriptPart2/homework/easy3.ts @@ -3,14 +3,14 @@ // Нужно заменить 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; -}; +}; \ No newline at end of file diff --git a/lessons/module2/1_TypescriptPart2/homework/medium1.ts b/lessons/module2/1_TypescriptPart2/homework/medium1.ts index 15b76fbe..ce7373bb 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..1560960f 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 = ( +export const getDefaultProps = ( component: React.ComponentType -): FIXME => { +): FIXME => { return component.defaultProps; -}; +}; \ No newline at end of file diff --git a/lessons/module2/1_TypescriptPart2/homework/medium3.ts b/lessons/module2/1_TypescriptPart2/homework/medium3.ts index 71b9f1e4..6242921e 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,8 @@ 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" + ); \ No newline at end of file From a02f6cb982f7605c20dcefcedf09493507d25d5a Mon Sep 17 00:00:00 2001 From: "d.golovko" Date: Tue, 11 Apr 2023 23:49:09 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D1=8F?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lessons/module2/1_TypescriptPart2/homework/easy1.ts | 6 ++++-- lessons/module2/1_TypescriptPart2/homework/easy2.ts | 2 +- lessons/module2/1_TypescriptPart2/homework/easy3.ts | 6 +++--- lessons/module2/1_TypescriptPart2/homework/medium1.ts | 2 +- lessons/module2/1_TypescriptPart2/homework/medium2.ts | 4 ++-- lessons/module2/1_TypescriptPart2/homework/medium3.ts | 9 ++++++--- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lessons/module2/1_TypescriptPart2/homework/easy1.ts b/lessons/module2/1_TypescriptPart2/homework/easy1.ts index 00f6be10..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 UserOrderStates = Exclude +type UserOrderStates = Exclude; const orderStates = [ "initial", @@ -15,7 +15,9 @@ const orderStates = [ type OrderState = typeof orderStates[number]; -export const getUserOrderStates = (orderStates: OrderState[]): UserOrderStates => { +export const getUserOrderStates = ( + orderStates: OrderState[] +): UserOrderStates => { const filteredStates = [] as UserOrderStates; orderStates.forEach((element) => { if (element !== "buyingSupplies" && element !== "producing") { diff --git a/lessons/module2/1_TypescriptPart2/homework/easy2.ts b/lessons/module2/1_TypescriptPart2/homework/easy2.ts index 07763fcc..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 OrderState = {[P in keyof Order]: Order[P]}["state"]; +type OrderState = { [P in keyof Order]: Order[P] }["state"]; type Order = | { diff --git a/lessons/module2/1_TypescriptPart2/homework/easy3.ts b/lessons/module2/1_TypescriptPart2/homework/easy3.ts index 527f0a8b..56823c5b 100644 --- a/lessons/module2/1_TypescriptPart2/homework/easy3.ts +++ b/lessons/module2/1_TypescriptPart2/homework/easy3.ts @@ -3,14 +3,14 @@ // Нужно заменить FIXME на соответствующий тип // eslint-disable-next-line @typescript-eslint/no-explicit-any -type FIXME = Omit; +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; -}; \ No newline at end of file +}; diff --git a/lessons/module2/1_TypescriptPart2/homework/medium1.ts b/lessons/module2/1_TypescriptPart2/homework/medium1.ts index ce7373bb..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 = Extract | null; +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 1560960f..9164a7f4 100644 --- a/lessons/module2/1_TypescriptPart2/homework/medium2.ts +++ b/lessons/module2/1_TypescriptPart2/homework/medium2.ts @@ -5,8 +5,8 @@ import React from "react"; type FIXME = T extends infer I ? I : never; // Hint: infer -export const getDefaultProps = ( +export const getDefaultProps = ( component: React.ComponentType ): FIXME => { return component.defaultProps; -}; \ No newline at end of file +}; diff --git a/lessons/module2/1_TypescriptPart2/homework/medium3.ts b/lessons/module2/1_TypescriptPart2/homework/medium3.ts index 6242921e..98898bde 100644 --- a/lessons/module2/1_TypescriptPart2/homework/medium3.ts +++ b/lessons/module2/1_TypescriptPart2/homework/medium3.ts @@ -11,7 +11,10 @@ const orderStates = [ type OrderState = typeof orderStates[number]; // Hint: type guards -export const getUserOrderStates = (orderStates: readonly OrderState[]): FIXME[] => +export const getUserOrderStates = ( + orderStates: readonly OrderState[] +): FIXME[] => orderStates.filter( - (state): state is FIXME => state !== "buyingSupplies" && state !== "producing" - ); \ No newline at end of file + (state): state is FIXME => + state !== "buyingSupplies" && state !== "producing" + );