From 65e21f870ab436c4f54f86d22832c7209eeb7bb2 Mon Sep 17 00:00:00 2001 From: Matt Pocock Date: Wed, 16 Aug 2023 10:00:43 +0100 Subject: [PATCH] 2023-08-16T09:00:43.457Z --- .../037-introduction-to-unions.problem.ts | 0 .../037-introduction-to-unions.solution.ts | 0 .../038-literal-types.problem.ts | 0 .../038-literal-types.solution.1.ts | 0 .../038-literal-types.solution.2.ts | 0 .../039-combining-unions.problem.ts | 0 .../039-combining-unions.solution.ts | 0 .../040-how-big-can-a-union-be.explainer.ts | 0 .../041-literals-vs-wider-types.explainer.ts | 0 ...-narrowing-unions-with-typeof.explainer.ts | 0 ...43-narrowing-with-if-statements.problem.ts | 0 ...narrowing-with-if-statements.solution.1.ts | 0 ...narrowing-with-if-statements.solution.2.ts | 0 ...narrowing-with-if-statements.solution.3.ts | 0 ...narrowing-with-if-statements.solution.4.ts | 0 ...narrowing-with-if-statements.solution.5.ts | 0 ...rowing-with-boolean-wont-work.explainer.ts | 0 .../045-throwing-errors-to-narrow.problem.ts | 0 .../045-throwing-errors-to-narrow.solution.ts | 0 ...wing-with-instanceof-statements.problem.ts | 0 ...ing-with-instanceof-statements.solution.ts | 0 ...47-narrowing-with-in-statements.problem.ts | 0 ...7-narrowing-with-in-statements.solution.ts | 0 ...48-narrowing-unknown-to-a-value.problem.ts | 0 ...8-narrowing-unknown-to-a-value.solution.ts | 0 .../049-narrowing-with-ternaries.problem.ts | 0 .../049-narrowing-with-ternaries.solution.ts | 0 ...rrowing-with-nullish-coalescing.problem.ts | 0 ...rowing-with-nullish-coalescing.solution.ts | 0 ...1-intro-to-discriminated-unions.problem.ts | 0 ...-intro-to-discriminated-unions.solution.ts | 0 ...ructuring-a-discriminated-union.problem.ts | 0 ...ucturing-a-discriminated-union.solution.ts | 0 ...d-union-with-a-switch-statement.problem.ts | 0 ...-union-with-a-switch-statement.solution.ts | 0 ...54-narrowing-with-switch-true.explainer.ts | 0 ...ructuring-a-discriminated-tuple.problem.ts | 0 ...ucturing-a-discriminated-tuple.solution.ts | 0 .../056-discriminated-booleans.problem.ts | 0 .../056-discriminated-booleans.solution.ts | 0 ...tend-object-using-intersections.problem.ts | 38 +++++++++++++++++ ...end-object-using-intersections.solution.ts | 39 +++++++++++++++++ ...-extend-object-using-interfaces.problem.ts | 39 +++++++++++++++++ ...tend-object-using-interfaces.solution.1.ts | 39 +++++++++++++++++ ...tend-object-using-interfaces.solution.2.ts | 42 +++++++++++++++++++ ...-intersections-and-interfaces.explainer.ts | 1 + .../060-index-signatures.problem.ts | 5 +++ .../060-index-signatures.solution.1.ts | 9 ++++ .../060-index-signatures.solution.2.ts | 9 ++++ .../060-index-signatures.solution.3.ts | 7 ++++ .../060-index-signatures.solution.4.ts | 5 +++ ...ex-signatures-with-defined-keys.problem.ts | 16 +++++++ ...signatures-with-defined-keys.solution.1.ts | 16 +++++++ ...signatures-with-defined-keys.solution.2.ts | 19 +++++++++ ...-record-type-with-union-as-keys.problem.ts | 0 ...record-type-with-union-as-keys.solution.ts | 0 ...claration-merging-of-interfaces.problem.ts | 19 +++++++++ ...laration-merging-of-interfaces.solution.ts | 15 +++++++ .../064-pick-type-helper.problem.ts | 18 ++++++++ .../064-pick-type-helper.solution.1.ts | 21 ++++++++++ .../064-pick-type-helper.solution.2.ts | 20 +++++++++ .../065-omit-type-helper.problem.ts | 24 +++++++++++ .../065-omit-type-helper.solution.1.ts | 29 +++++++++++++ .../065-omit-type-helper.solution.2.ts | 24 +++++++++++ .../066-partial-type-helper.problem.ts | 34 +++++++++++++++ .../066-partial-type-helper.solution.ts | 37 ++++++++++++++++ .../067-required-type-helper.explainer.ts | 8 ++++ 67 files changed, 533 insertions(+) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/037-introduction-to-unions.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/037-introduction-to-unions.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/038-literal-types.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/038-literal-types.solution.1.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/038-literal-types.solution.2.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/039-combining-unions.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/039-combining-unions.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/040-how-big-can-a-union-be.explainer.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/041-literals-vs-wider-types.explainer.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/042-narrowing-unions-with-typeof.explainer.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/043-narrowing-with-if-statements.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/043-narrowing-with-if-statements.solution.1.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/043-narrowing-with-if-statements.solution.2.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/043-narrowing-with-if-statements.solution.3.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/043-narrowing-with-if-statements.solution.4.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/043-narrowing-with-if-statements.solution.5.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/044-narrowing-with-boolean-wont-work.explainer.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/045-throwing-errors-to-narrow.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/045-throwing-errors-to-narrow.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/046-narrowing-with-instanceof-statements.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/046-narrowing-with-instanceof-statements.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/047-narrowing-with-in-statements.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/047-narrowing-with-in-statements.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/048-narrowing-unknown-to-a-value.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/048-narrowing-unknown-to-a-value.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/049-narrowing-with-ternaries.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/049-narrowing-with-ternaries.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/050-narrowing-with-nullish-coalescing.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/050-narrowing-with-nullish-coalescing.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/051-intro-to-discriminated-unions.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/051-intro-to-discriminated-unions.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/052-destructuring-a-discriminated-union.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/052-destructuring-a-discriminated-union.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/053-narrowing-a-discriminated-union-with-a-switch-statement.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/053-narrowing-a-discriminated-union-with-a-switch-statement.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/054-narrowing-with-switch-true.explainer.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/055-destructuring-a-discriminated-tuple.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/055-destructuring-a-discriminated-tuple.solution.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/056-discriminated-booleans.problem.ts (100%) rename src/{038-unions-and-narrowing => 018-unions-and-narrowing}/056-discriminated-booleans.solution.ts (100%) create mode 100644 src/020-sets-of-types/057-extend-object-using-intersections.problem.ts create mode 100644 src/020-sets-of-types/057-extend-object-using-intersections.solution.ts create mode 100644 src/020-sets-of-types/058-extend-object-using-interfaces.problem.ts create mode 100644 src/020-sets-of-types/058-extend-object-using-interfaces.solution.1.ts create mode 100644 src/020-sets-of-types/058-extend-object-using-interfaces.solution.2.ts create mode 100644 src/020-sets-of-types/059-compare-between-intersections-and-interfaces.explainer.ts create mode 100644 src/020-sets-of-types/060-index-signatures.problem.ts create mode 100644 src/020-sets-of-types/060-index-signatures.solution.1.ts create mode 100644 src/020-sets-of-types/060-index-signatures.solution.2.ts create mode 100644 src/020-sets-of-types/060-index-signatures.solution.3.ts create mode 100644 src/020-sets-of-types/060-index-signatures.solution.4.ts create mode 100644 src/020-sets-of-types/061-index-signatures-with-defined-keys.problem.ts create mode 100644 src/020-sets-of-types/061-index-signatures-with-defined-keys.solution.1.ts create mode 100644 src/020-sets-of-types/061-index-signatures-with-defined-keys.solution.2.ts create mode 100644 src/020-sets-of-types/062-record-type-with-union-as-keys.problem.ts create mode 100644 src/020-sets-of-types/062-record-type-with-union-as-keys.solution.ts create mode 100644 src/020-sets-of-types/063-declaration-merging-of-interfaces.problem.ts create mode 100644 src/020-sets-of-types/063-declaration-merging-of-interfaces.solution.ts create mode 100644 src/020-sets-of-types/064-pick-type-helper.problem.ts create mode 100644 src/020-sets-of-types/064-pick-type-helper.solution.1.ts create mode 100644 src/020-sets-of-types/064-pick-type-helper.solution.2.ts create mode 100644 src/020-sets-of-types/065-omit-type-helper.problem.ts create mode 100644 src/020-sets-of-types/065-omit-type-helper.solution.1.ts create mode 100644 src/020-sets-of-types/065-omit-type-helper.solution.2.ts create mode 100644 src/020-sets-of-types/066-partial-type-helper.problem.ts create mode 100644 src/020-sets-of-types/066-partial-type-helper.solution.ts create mode 100644 src/020-sets-of-types/067-required-type-helper.explainer.ts diff --git a/src/038-unions-and-narrowing/037-introduction-to-unions.problem.ts b/src/018-unions-and-narrowing/037-introduction-to-unions.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/037-introduction-to-unions.problem.ts rename to src/018-unions-and-narrowing/037-introduction-to-unions.problem.ts diff --git a/src/038-unions-and-narrowing/037-introduction-to-unions.solution.ts b/src/018-unions-and-narrowing/037-introduction-to-unions.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/037-introduction-to-unions.solution.ts rename to src/018-unions-and-narrowing/037-introduction-to-unions.solution.ts diff --git a/src/038-unions-and-narrowing/038-literal-types.problem.ts b/src/018-unions-and-narrowing/038-literal-types.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/038-literal-types.problem.ts rename to src/018-unions-and-narrowing/038-literal-types.problem.ts diff --git a/src/038-unions-and-narrowing/038-literal-types.solution.1.ts b/src/018-unions-and-narrowing/038-literal-types.solution.1.ts similarity index 100% rename from src/038-unions-and-narrowing/038-literal-types.solution.1.ts rename to src/018-unions-and-narrowing/038-literal-types.solution.1.ts diff --git a/src/038-unions-and-narrowing/038-literal-types.solution.2.ts b/src/018-unions-and-narrowing/038-literal-types.solution.2.ts similarity index 100% rename from src/038-unions-and-narrowing/038-literal-types.solution.2.ts rename to src/018-unions-and-narrowing/038-literal-types.solution.2.ts diff --git a/src/038-unions-and-narrowing/039-combining-unions.problem.ts b/src/018-unions-and-narrowing/039-combining-unions.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/039-combining-unions.problem.ts rename to src/018-unions-and-narrowing/039-combining-unions.problem.ts diff --git a/src/038-unions-and-narrowing/039-combining-unions.solution.ts b/src/018-unions-and-narrowing/039-combining-unions.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/039-combining-unions.solution.ts rename to src/018-unions-and-narrowing/039-combining-unions.solution.ts diff --git a/src/038-unions-and-narrowing/040-how-big-can-a-union-be.explainer.ts b/src/018-unions-and-narrowing/040-how-big-can-a-union-be.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/040-how-big-can-a-union-be.explainer.ts rename to src/018-unions-and-narrowing/040-how-big-can-a-union-be.explainer.ts diff --git a/src/038-unions-and-narrowing/041-literals-vs-wider-types.explainer.ts b/src/018-unions-and-narrowing/041-literals-vs-wider-types.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/041-literals-vs-wider-types.explainer.ts rename to src/018-unions-and-narrowing/041-literals-vs-wider-types.explainer.ts diff --git a/src/038-unions-and-narrowing/042-narrowing-unions-with-typeof.explainer.ts b/src/018-unions-and-narrowing/042-narrowing-unions-with-typeof.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/042-narrowing-unions-with-typeof.explainer.ts rename to src/018-unions-and-narrowing/042-narrowing-unions-with-typeof.explainer.ts diff --git a/src/038-unions-and-narrowing/043-narrowing-with-if-statements.problem.ts b/src/018-unions-and-narrowing/043-narrowing-with-if-statements.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/043-narrowing-with-if-statements.problem.ts rename to src/018-unions-and-narrowing/043-narrowing-with-if-statements.problem.ts diff --git a/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.1.ts b/src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.1.ts similarity index 100% rename from src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.1.ts rename to src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.1.ts diff --git a/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.2.ts b/src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.2.ts similarity index 100% rename from src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.2.ts rename to src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.2.ts diff --git a/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.3.ts b/src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.3.ts similarity index 100% rename from src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.3.ts rename to src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.3.ts diff --git a/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.4.ts b/src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.4.ts similarity index 100% rename from src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.4.ts rename to src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.4.ts diff --git a/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.5.ts b/src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.5.ts similarity index 100% rename from src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.5.ts rename to src/018-unions-and-narrowing/043-narrowing-with-if-statements.solution.5.ts diff --git a/src/038-unions-and-narrowing/044-narrowing-with-boolean-wont-work.explainer.ts b/src/018-unions-and-narrowing/044-narrowing-with-boolean-wont-work.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/044-narrowing-with-boolean-wont-work.explainer.ts rename to src/018-unions-and-narrowing/044-narrowing-with-boolean-wont-work.explainer.ts diff --git a/src/038-unions-and-narrowing/045-throwing-errors-to-narrow.problem.ts b/src/018-unions-and-narrowing/045-throwing-errors-to-narrow.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/045-throwing-errors-to-narrow.problem.ts rename to src/018-unions-and-narrowing/045-throwing-errors-to-narrow.problem.ts diff --git a/src/038-unions-and-narrowing/045-throwing-errors-to-narrow.solution.ts b/src/018-unions-and-narrowing/045-throwing-errors-to-narrow.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/045-throwing-errors-to-narrow.solution.ts rename to src/018-unions-and-narrowing/045-throwing-errors-to-narrow.solution.ts diff --git a/src/038-unions-and-narrowing/046-narrowing-with-instanceof-statements.problem.ts b/src/018-unions-and-narrowing/046-narrowing-with-instanceof-statements.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/046-narrowing-with-instanceof-statements.problem.ts rename to src/018-unions-and-narrowing/046-narrowing-with-instanceof-statements.problem.ts diff --git a/src/038-unions-and-narrowing/046-narrowing-with-instanceof-statements.solution.ts b/src/018-unions-and-narrowing/046-narrowing-with-instanceof-statements.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/046-narrowing-with-instanceof-statements.solution.ts rename to src/018-unions-and-narrowing/046-narrowing-with-instanceof-statements.solution.ts diff --git a/src/038-unions-and-narrowing/047-narrowing-with-in-statements.problem.ts b/src/018-unions-and-narrowing/047-narrowing-with-in-statements.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/047-narrowing-with-in-statements.problem.ts rename to src/018-unions-and-narrowing/047-narrowing-with-in-statements.problem.ts diff --git a/src/038-unions-and-narrowing/047-narrowing-with-in-statements.solution.ts b/src/018-unions-and-narrowing/047-narrowing-with-in-statements.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/047-narrowing-with-in-statements.solution.ts rename to src/018-unions-and-narrowing/047-narrowing-with-in-statements.solution.ts diff --git a/src/038-unions-and-narrowing/048-narrowing-unknown-to-a-value.problem.ts b/src/018-unions-and-narrowing/048-narrowing-unknown-to-a-value.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/048-narrowing-unknown-to-a-value.problem.ts rename to src/018-unions-and-narrowing/048-narrowing-unknown-to-a-value.problem.ts diff --git a/src/038-unions-and-narrowing/048-narrowing-unknown-to-a-value.solution.ts b/src/018-unions-and-narrowing/048-narrowing-unknown-to-a-value.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/048-narrowing-unknown-to-a-value.solution.ts rename to src/018-unions-and-narrowing/048-narrowing-unknown-to-a-value.solution.ts diff --git a/src/038-unions-and-narrowing/049-narrowing-with-ternaries.problem.ts b/src/018-unions-and-narrowing/049-narrowing-with-ternaries.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/049-narrowing-with-ternaries.problem.ts rename to src/018-unions-and-narrowing/049-narrowing-with-ternaries.problem.ts diff --git a/src/038-unions-and-narrowing/049-narrowing-with-ternaries.solution.ts b/src/018-unions-and-narrowing/049-narrowing-with-ternaries.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/049-narrowing-with-ternaries.solution.ts rename to src/018-unions-and-narrowing/049-narrowing-with-ternaries.solution.ts diff --git a/src/038-unions-and-narrowing/050-narrowing-with-nullish-coalescing.problem.ts b/src/018-unions-and-narrowing/050-narrowing-with-nullish-coalescing.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/050-narrowing-with-nullish-coalescing.problem.ts rename to src/018-unions-and-narrowing/050-narrowing-with-nullish-coalescing.problem.ts diff --git a/src/038-unions-and-narrowing/050-narrowing-with-nullish-coalescing.solution.ts b/src/018-unions-and-narrowing/050-narrowing-with-nullish-coalescing.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/050-narrowing-with-nullish-coalescing.solution.ts rename to src/018-unions-and-narrowing/050-narrowing-with-nullish-coalescing.solution.ts diff --git a/src/038-unions-and-narrowing/051-intro-to-discriminated-unions.problem.ts b/src/018-unions-and-narrowing/051-intro-to-discriminated-unions.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/051-intro-to-discriminated-unions.problem.ts rename to src/018-unions-and-narrowing/051-intro-to-discriminated-unions.problem.ts diff --git a/src/038-unions-and-narrowing/051-intro-to-discriminated-unions.solution.ts b/src/018-unions-and-narrowing/051-intro-to-discriminated-unions.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/051-intro-to-discriminated-unions.solution.ts rename to src/018-unions-and-narrowing/051-intro-to-discriminated-unions.solution.ts diff --git a/src/038-unions-and-narrowing/052-destructuring-a-discriminated-union.problem.ts b/src/018-unions-and-narrowing/052-destructuring-a-discriminated-union.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/052-destructuring-a-discriminated-union.problem.ts rename to src/018-unions-and-narrowing/052-destructuring-a-discriminated-union.problem.ts diff --git a/src/038-unions-and-narrowing/052-destructuring-a-discriminated-union.solution.ts b/src/018-unions-and-narrowing/052-destructuring-a-discriminated-union.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/052-destructuring-a-discriminated-union.solution.ts rename to src/018-unions-and-narrowing/052-destructuring-a-discriminated-union.solution.ts diff --git a/src/038-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.problem.ts b/src/018-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.problem.ts rename to src/018-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.problem.ts diff --git a/src/038-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.solution.ts b/src/018-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.solution.ts rename to src/018-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.solution.ts diff --git a/src/038-unions-and-narrowing/054-narrowing-with-switch-true.explainer.ts b/src/018-unions-and-narrowing/054-narrowing-with-switch-true.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/054-narrowing-with-switch-true.explainer.ts rename to src/018-unions-and-narrowing/054-narrowing-with-switch-true.explainer.ts diff --git a/src/038-unions-and-narrowing/055-destructuring-a-discriminated-tuple.problem.ts b/src/018-unions-and-narrowing/055-destructuring-a-discriminated-tuple.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/055-destructuring-a-discriminated-tuple.problem.ts rename to src/018-unions-and-narrowing/055-destructuring-a-discriminated-tuple.problem.ts diff --git a/src/038-unions-and-narrowing/055-destructuring-a-discriminated-tuple.solution.ts b/src/018-unions-and-narrowing/055-destructuring-a-discriminated-tuple.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/055-destructuring-a-discriminated-tuple.solution.ts rename to src/018-unions-and-narrowing/055-destructuring-a-discriminated-tuple.solution.ts diff --git a/src/038-unions-and-narrowing/056-discriminated-booleans.problem.ts b/src/018-unions-and-narrowing/056-discriminated-booleans.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/056-discriminated-booleans.problem.ts rename to src/018-unions-and-narrowing/056-discriminated-booleans.problem.ts diff --git a/src/038-unions-and-narrowing/056-discriminated-booleans.solution.ts b/src/018-unions-and-narrowing/056-discriminated-booleans.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/056-discriminated-booleans.solution.ts rename to src/018-unions-and-narrowing/056-discriminated-booleans.solution.ts diff --git a/src/020-sets-of-types/057-extend-object-using-intersections.problem.ts b/src/020-sets-of-types/057-extend-object-using-intersections.problem.ts new file mode 100644 index 0000000..f7dacd1 --- /dev/null +++ b/src/020-sets-of-types/057-extend-object-using-intersections.problem.ts @@ -0,0 +1,38 @@ +type User = { + id: string; + createdAt: Date; + name: string; + email: string; +}; + +type Product = { + id: string; + createdAt: Date; + name: string; + price: number; +}; + +type tests = [ + Expect< + Extends< + User, + { + id: string; + createdAt: Date; + name: string; + email: string; + } + > + >, + Expect< + Extends< + Product, + { + id: string; + createdAt: Date; + name: string; + price: number; + } + > + >, +]; diff --git a/src/020-sets-of-types/057-extend-object-using-intersections.solution.ts b/src/020-sets-of-types/057-extend-object-using-intersections.solution.ts new file mode 100644 index 0000000..f329d64 --- /dev/null +++ b/src/020-sets-of-types/057-extend-object-using-intersections.solution.ts @@ -0,0 +1,39 @@ +type BaseEntity = { + id: string; + createdAt: Date; +}; + +type User = { + name: string; + email: string; +} & BaseEntity; + +type Product = { + name: string; + price: number; +} & BaseEntity; + +type tests = [ + Expect< + Extends< + User, + { + id: string; + createdAt: Date; + name: string; + email: string; + } + > + >, + Expect< + Extends< + Product, + { + id: string; + createdAt: Date; + name: string; + price: number; + } + > + >, +]; diff --git a/src/020-sets-of-types/058-extend-object-using-interfaces.problem.ts b/src/020-sets-of-types/058-extend-object-using-interfaces.problem.ts new file mode 100644 index 0000000..f329d64 --- /dev/null +++ b/src/020-sets-of-types/058-extend-object-using-interfaces.problem.ts @@ -0,0 +1,39 @@ +type BaseEntity = { + id: string; + createdAt: Date; +}; + +type User = { + name: string; + email: string; +} & BaseEntity; + +type Product = { + name: string; + price: number; +} & BaseEntity; + +type tests = [ + Expect< + Extends< + User, + { + id: string; + createdAt: Date; + name: string; + email: string; + } + > + >, + Expect< + Extends< + Product, + { + id: string; + createdAt: Date; + name: string; + price: number; + } + > + >, +]; diff --git a/src/020-sets-of-types/058-extend-object-using-interfaces.solution.1.ts b/src/020-sets-of-types/058-extend-object-using-interfaces.solution.1.ts new file mode 100644 index 0000000..b5c7668 --- /dev/null +++ b/src/020-sets-of-types/058-extend-object-using-interfaces.solution.1.ts @@ -0,0 +1,39 @@ +interface BaseEntity { + id: string; + createdAt: Date; +} + +interface User extends BaseEntity { + name: string; + email: string; +} + +interface Product extends BaseEntity { + name: string; + price: number; +} + +type tests = [ + Expect< + Extends< + User, + { + id: string; + createdAt: Date; + name: string; + email: string; + } + > + >, + Expect< + Extends< + Product, + { + id: string; + createdAt: Date; + name: string; + price: number; + } + > + >, +]; diff --git a/src/020-sets-of-types/058-extend-object-using-interfaces.solution.2.ts b/src/020-sets-of-types/058-extend-object-using-interfaces.solution.2.ts new file mode 100644 index 0000000..d02ee95 --- /dev/null +++ b/src/020-sets-of-types/058-extend-object-using-interfaces.solution.2.ts @@ -0,0 +1,42 @@ +interface WithId { + id: string; +} + +interface WithCreatedAt { + createdAt: Date; +} + +interface User extends WithId, WithCreatedAt { + name: string; + email: string; +} + +interface Product extends WithId, WithCreatedAt { + name: string; + price: number; +} + +type tests = [ + Expect< + Extends< + User, + { + id: string; + createdAt: Date; + name: string; + email: string; + } + > + >, + Expect< + Extends< + Product, + { + id: string; + createdAt: Date; + name: string; + price: number; + } + > + >, +]; diff --git a/src/020-sets-of-types/059-compare-between-intersections-and-interfaces.explainer.ts b/src/020-sets-of-types/059-compare-between-intersections-and-interfaces.explainer.ts new file mode 100644 index 0000000..1e1fc55 --- /dev/null +++ b/src/020-sets-of-types/059-compare-between-intersections-and-interfaces.explainer.ts @@ -0,0 +1 @@ +// https://github.com/microsoft/TypeScript/wiki/Performance#preferring-interfaces-over-intersections diff --git a/src/020-sets-of-types/060-index-signatures.problem.ts b/src/020-sets-of-types/060-index-signatures.problem.ts new file mode 100644 index 0000000..6e2fd48 --- /dev/null +++ b/src/020-sets-of-types/060-index-signatures.problem.ts @@ -0,0 +1,5 @@ +const scores = {}; + +scores.math = 95; +scores.english = 90; +scores.science = 85; diff --git a/src/020-sets-of-types/060-index-signatures.solution.1.ts b/src/020-sets-of-types/060-index-signatures.solution.1.ts new file mode 100644 index 0000000..1fa76b7 --- /dev/null +++ b/src/020-sets-of-types/060-index-signatures.solution.1.ts @@ -0,0 +1,9 @@ +type Scores = { + [key: string]: number; +}; + +const scores: Scores = {}; + +scores.math = 95; +scores.english = 90; +scores.science = 85; diff --git a/src/020-sets-of-types/060-index-signatures.solution.2.ts b/src/020-sets-of-types/060-index-signatures.solution.2.ts new file mode 100644 index 0000000..c2a9440 --- /dev/null +++ b/src/020-sets-of-types/060-index-signatures.solution.2.ts @@ -0,0 +1,9 @@ +interface Scores { + [key: string]: number; +} + +const scores: Scores = {}; + +scores.math = 95; +scores.english = 90; +scores.science = 85; diff --git a/src/020-sets-of-types/060-index-signatures.solution.3.ts b/src/020-sets-of-types/060-index-signatures.solution.3.ts new file mode 100644 index 0000000..a253f5a --- /dev/null +++ b/src/020-sets-of-types/060-index-signatures.solution.3.ts @@ -0,0 +1,7 @@ +const scores: { + [key: string]: number; +} = {}; + +scores.math = 95; +scores.english = 90; +scores.science = 85; diff --git a/src/020-sets-of-types/060-index-signatures.solution.4.ts b/src/020-sets-of-types/060-index-signatures.solution.4.ts new file mode 100644 index 0000000..0d6c36e --- /dev/null +++ b/src/020-sets-of-types/060-index-signatures.solution.4.ts @@ -0,0 +1,5 @@ +const scores: Record = {}; + +scores.math = 95; +scores.english = 90; +scores.science = 85; diff --git a/src/020-sets-of-types/061-index-signatures-with-defined-keys.problem.ts b/src/020-sets-of-types/061-index-signatures-with-defined-keys.problem.ts new file mode 100644 index 0000000..911cb43 --- /dev/null +++ b/src/020-sets-of-types/061-index-signatures-with-defined-keys.problem.ts @@ -0,0 +1,16 @@ +interface Scores { + [key: string]: number; + math: number; + english: number; + science: number; +} + +// @ts-expect-error science is missing! +const scores: Scores = { + math: 95, + english: 90, +}; + +scores.athletics = 100; +scores.french = 75; +scores.spanish = 70; diff --git a/src/020-sets-of-types/061-index-signatures-with-defined-keys.solution.1.ts b/src/020-sets-of-types/061-index-signatures-with-defined-keys.solution.1.ts new file mode 100644 index 0000000..911cb43 --- /dev/null +++ b/src/020-sets-of-types/061-index-signatures-with-defined-keys.solution.1.ts @@ -0,0 +1,16 @@ +interface Scores { + [key: string]: number; + math: number; + english: number; + science: number; +} + +// @ts-expect-error science is missing! +const scores: Scores = { + math: 95, + english: 90, +}; + +scores.athletics = 100; +scores.french = 75; +scores.spanish = 70; diff --git a/src/020-sets-of-types/061-index-signatures-with-defined-keys.solution.2.ts b/src/020-sets-of-types/061-index-signatures-with-defined-keys.solution.2.ts new file mode 100644 index 0000000..05e6d6e --- /dev/null +++ b/src/020-sets-of-types/061-index-signatures-with-defined-keys.solution.2.ts @@ -0,0 +1,19 @@ +interface RequiredScores { + math: number; + english: number; + science: number; +} + +interface Scores extends RequiredScores { + [key: string]: number; +} + +// @ts-expect-error science is missing! +const scores: Scores = { + math: 95, + english: 90, +}; + +scores.athletics = 100; +scores.french = 75; +scores.spanish = 70; diff --git a/src/020-sets-of-types/062-record-type-with-union-as-keys.problem.ts b/src/020-sets-of-types/062-record-type-with-union-as-keys.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/020-sets-of-types/062-record-type-with-union-as-keys.solution.ts b/src/020-sets-of-types/062-record-type-with-union-as-keys.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/020-sets-of-types/063-declaration-merging-of-interfaces.problem.ts b/src/020-sets-of-types/063-declaration-merging-of-interfaces.problem.ts new file mode 100644 index 0000000..07f1ee8 --- /dev/null +++ b/src/020-sets-of-types/063-declaration-merging-of-interfaces.problem.ts @@ -0,0 +1,19 @@ +interface Logger { + log(message: string, level: number): void; +} + +interface Logger { + log(message: string): void; +} + +const myLogger: Logger = { + log: (message: string) => { + console.log(message); + }, +}; + +myLogger.log( + "My message", + // @ts-expect-error Level is NOT needed + 123, +); diff --git a/src/020-sets-of-types/063-declaration-merging-of-interfaces.solution.ts b/src/020-sets-of-types/063-declaration-merging-of-interfaces.solution.ts new file mode 100644 index 0000000..32cfb33 --- /dev/null +++ b/src/020-sets-of-types/063-declaration-merging-of-interfaces.solution.ts @@ -0,0 +1,15 @@ +type Logger = { + log(message: string): void; +}; + +const myLogger: Logger = { + log: (message: string) => { + console.log(message); + }, +}; + +myLogger.log( + "My message", + // @ts-expect-error Level is NOT needed + 123, +); diff --git a/src/020-sets-of-types/064-pick-type-helper.problem.ts b/src/020-sets-of-types/064-pick-type-helper.problem.ts new file mode 100644 index 0000000..7a0f1c5 --- /dev/null +++ b/src/020-sets-of-types/064-pick-type-helper.problem.ts @@ -0,0 +1,18 @@ +interface User { + id: string; + name: string; + email: string; + role: string; +} + +const fetchUser = async () => { + const response = await fetch("/api/user"); + const user = await response.json(); + return user; +}; + +const example = async () => { + const user = await fetchUser(); + + type test = Expect>; +}; diff --git a/src/020-sets-of-types/064-pick-type-helper.solution.1.ts b/src/020-sets-of-types/064-pick-type-helper.solution.1.ts new file mode 100644 index 0000000..f55a9fa --- /dev/null +++ b/src/020-sets-of-types/064-pick-type-helper.solution.1.ts @@ -0,0 +1,21 @@ +interface NameAndEmail { + name: string; + email: string; +} + +interface User extends NameAndEmail { + id: string; + role: string; +} + +const fetchUser = async (): Promise => { + const response = await fetch("/api/user"); + const user = await response.json(); + return user; +}; + +const example = async () => { + const user = await fetchUser(); + + type test = Expect>; +}; diff --git a/src/020-sets-of-types/064-pick-type-helper.solution.2.ts b/src/020-sets-of-types/064-pick-type-helper.solution.2.ts new file mode 100644 index 0000000..38c80ad --- /dev/null +++ b/src/020-sets-of-types/064-pick-type-helper.solution.2.ts @@ -0,0 +1,20 @@ +interface User { + id: string; + name: string; + email: string; + role: string; +} + +type OnlyNameAndEmail = Pick; + +const fetchUser = async (): Promise => { + const response = await fetch("/api/user"); + const user = await response.json(); + return user; +}; + +const example = async () => { + const user = await fetchUser(); + + type test = Expect>; +}; diff --git a/src/020-sets-of-types/065-omit-type-helper.problem.ts b/src/020-sets-of-types/065-omit-type-helper.problem.ts new file mode 100644 index 0000000..8c3577d --- /dev/null +++ b/src/020-sets-of-types/065-omit-type-helper.problem.ts @@ -0,0 +1,24 @@ +interface Product { + id: number; + name: string; + price: number; + description: string; +} + +const addProduct = (productInfo: Product) => { + // Do something with the productInfo +}; + +addProduct({ + name: "Book", + price: 12.99, + description: "A book about Dragons", +}); + +addProduct({ + // @ts-expect-error + id: 1, + name: "Book", + price: 12.99, + description: "A book about Dragons", +}); diff --git a/src/020-sets-of-types/065-omit-type-helper.solution.1.ts b/src/020-sets-of-types/065-omit-type-helper.solution.1.ts new file mode 100644 index 0000000..f8e6ad1 --- /dev/null +++ b/src/020-sets-of-types/065-omit-type-helper.solution.1.ts @@ -0,0 +1,29 @@ +interface WithId { + id: number; +} + +interface ProductInfo { + name: string; + price: number; + description: string; +} + +interface Product extends WithId, ProductInfo {} + +const addProduct = (productInfo: ProductInfo) => { + // Do something with the productInfo +}; + +addProduct({ + name: "Book", + price: 12.99, + description: "A book about Dragons", +}); + +addProduct({ + // @ts-expect-error + id: 1, + name: "Book", + price: 12.99, + description: "A book about Dragons", +}); diff --git a/src/020-sets-of-types/065-omit-type-helper.solution.2.ts b/src/020-sets-of-types/065-omit-type-helper.solution.2.ts new file mode 100644 index 0000000..4351a6f --- /dev/null +++ b/src/020-sets-of-types/065-omit-type-helper.solution.2.ts @@ -0,0 +1,24 @@ +interface Product { + id: number; + name: string; + price: number; + description: string; +} + +const addProduct = (productInfo: Omit) => { + // Do something with the productInfo +}; + +addProduct({ + name: "Book", + price: 12.99, + description: "A book about Dragons", +}); + +addProduct({ + // @ts-expect-error + id: 1, + name: "Book", + price: 12.99, + description: "A book about Dragons", +}); diff --git a/src/020-sets-of-types/066-partial-type-helper.problem.ts b/src/020-sets-of-types/066-partial-type-helper.problem.ts new file mode 100644 index 0000000..7370405 --- /dev/null +++ b/src/020-sets-of-types/066-partial-type-helper.problem.ts @@ -0,0 +1,34 @@ +interface Product { + id: number; + name: string; + price: number; + description: string; +} + +const updateProduct = (id: number, productInfo: Omit) => { + // Do something with the productInfo +}; + +// Should be able to update individual pieces of information +updateProduct(1, { + name: "Book", +}); + +updateProduct(1, { + price: 12.99, +}); + +updateProduct(1, { + description: "A book about Dragons", +}); + +// Should be able to update more than one piece of info at once +updateProduct(1, { + name: "Book", + price: 12.99, +}); + +updateProduct(1, { + name: "Book", + description: "A book about Dragons", +}); diff --git a/src/020-sets-of-types/066-partial-type-helper.solution.ts b/src/020-sets-of-types/066-partial-type-helper.solution.ts new file mode 100644 index 0000000..ea9fbf7 --- /dev/null +++ b/src/020-sets-of-types/066-partial-type-helper.solution.ts @@ -0,0 +1,37 @@ +interface Product { + id: number; + name: string; + price: number; + description: string; +} + +const updateProduct = ( + id: number, + productInfo: Partial>, +) => { + // Do something with the productInfo +}; + +// Should be able to update individual pieces of information +updateProduct(1, { + name: "Book", +}); + +updateProduct(1, { + price: 12.99, +}); + +updateProduct(1, { + description: "A book about Dragons", +}); + +// Should be able to update more than one piece of info at once +updateProduct(1, { + name: "Book", + price: 12.99, +}); + +updateProduct(1, { + name: "Book", + description: "A book about Dragons", +}); diff --git a/src/020-sets-of-types/067-required-type-helper.explainer.ts b/src/020-sets-of-types/067-required-type-helper.explainer.ts new file mode 100644 index 0000000..d8f0c31 --- /dev/null +++ b/src/020-sets-of-types/067-required-type-helper.explainer.ts @@ -0,0 +1,8 @@ +type Coordinates = { + x?: number; + y?: number; +}; + +type CoordinatesRequired = Required; + +type test = Expect>;