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
3 changes: 2 additions & 1 deletion lessons/module2/1_TypescriptPart2/homework/easy1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Нужно заменить FIXME на тип который вычисляется на освове OrderState

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

type FIXME = Array<Exclude<OrderState, "buyingSupplies" | "producing">>;

const orderStates = [
"initial",
Expand Down
2 changes: 1 addition & 1 deletion 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 FIXME = Order["state"];

type Order =
| {
Expand Down
7 changes: 5 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,16 @@
// Нужно заменить FIXME на соответствующий тип

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FIXME = any;
type FIXME<T extends Record<any, any>, K extends keyof T> = Pick<
T,
Exclude<keyof T, K>
>;

// 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" | "inWork" }> | null;

type Order =
| {
Expand Down
4 changes: 2 additions & 2 deletions lessons/module2/1_TypescriptPart2/homework/medium2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// Нужно заменить FIXME на правильный тип

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FIXME = any;
type FIXME<T> = T extends (...args: any[]) => infer U ? U : T;

// Hint: infer
export const getDefaultProps = <T>(
component: React.ComponentType<T>
): FIXME => {
): FIXME<any> => {
return component.defaultProps;
};
4 changes: 3 additions & 1 deletion lessons/module2/1_TypescriptPart2/homework/medium3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FIXME = any;
type FIXME = Array<
Exclude<OrderState, { state: "initial" | "inWork" | "fullfilled" }>
>;

const orderStates = [
"initial",
Expand Down