diff --git a/src/038-unions-and-narrowing/039-combining-unions.problem.ts b/src/038-unions-and-narrowing/039-combining-unions.problem.ts new file mode 100644 index 0000000..2bcc3d6 --- /dev/null +++ b/src/038-unions-and-narrowing/039-combining-unions.problem.ts @@ -0,0 +1,21 @@ +type HttpCode = "400" | "401" | "404" | "500" | "200" | "201" | "204"; + +const handleErrorCase = (code: string) => { + // An imaginary function where we only handle the errors + + type test = Expect>; +}; + +const handleSuccessCase = (code: string) => { + // An imaginary function where we only handle the success cases + + type test = Expect>; +}; + +const handleAllCase = (code: HttpCode) => { + // An imaginary function where we handle all the cases + + type test = Expect< + Equal + >; +}; diff --git a/src/038-unions-and-narrowing/039-combining-unions.solution.ts b/src/038-unions-and-narrowing/039-combining-unions.solution.ts new file mode 100644 index 0000000..374c7f0 --- /dev/null +++ b/src/038-unions-and-narrowing/039-combining-unions.solution.ts @@ -0,0 +1,24 @@ +type SuccessCode = "200" | "201" | "204"; +type ErrorCode = "400" | "401" | "404" | "500"; + +type HttpCode = SuccessCode | ErrorCode; + +const handleErrorCase = (code: ErrorCode) => { + // An imaginary function where we only handle the errors + + type test = Expect>; +}; + +const handleSuccessCase = (code: SuccessCode) => { + // An imaginary function where we only handle the success cases + + type test = Expect>; +}; + +const handleAllCase = (code: HttpCode) => { + // An imaginary function where we handle all the cases + + type test = Expect< + Equal + >; +}; diff --git a/src/038-unions-and-narrowing/039-how-big-can-a-union-be.explainer.ts b/src/038-unions-and-narrowing/040-how-big-can-a-union-be.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/039-how-big-can-a-union-be.explainer.ts rename to src/038-unions-and-narrowing/040-how-big-can-a-union-be.explainer.ts diff --git a/src/038-unions-and-narrowing/040-literals-vs-wider-types.explainer.ts b/src/038-unions-and-narrowing/041-literals-vs-wider-types.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/040-literals-vs-wider-types.explainer.ts rename to src/038-unions-and-narrowing/041-literals-vs-wider-types.explainer.ts diff --git a/src/038-unions-and-narrowing/041-narrowing-unions-with-typeof.explainer.ts b/src/038-unions-and-narrowing/042-narrowing-unions-with-typeof.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/041-narrowing-unions-with-typeof.explainer.ts rename to src/038-unions-and-narrowing/042-narrowing-unions-with-typeof.explainer.ts diff --git a/src/038-unions-and-narrowing/042-narrowing-with-if-statements.problem.ts b/src/038-unions-and-narrowing/043-narrowing-with-if-statements.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/042-narrowing-with-if-statements.problem.ts rename to src/038-unions-and-narrowing/043-narrowing-with-if-statements.problem.ts diff --git a/src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.1.ts b/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.1.ts similarity index 100% rename from src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.1.ts rename to src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.1.ts diff --git a/src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.2.ts b/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.2.ts similarity index 100% rename from src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.2.ts rename to src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.2.ts diff --git a/src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.3.ts b/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.3.ts similarity index 100% rename from src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.3.ts rename to src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.3.ts diff --git a/src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.4.ts b/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.4.ts similarity index 100% rename from src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.4.ts rename to src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.4.ts diff --git a/src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.5.ts b/src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.5.ts similarity index 100% rename from src/038-unions-and-narrowing/042-narrowing-with-if-statements.solution.5.ts rename to src/038-unions-and-narrowing/043-narrowing-with-if-statements.solution.5.ts diff --git a/src/038-unions-and-narrowing/043-narrowing-with-boolean-wont-work.explainer.ts b/src/038-unions-and-narrowing/044-narrowing-with-boolean-wont-work.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/043-narrowing-with-boolean-wont-work.explainer.ts rename to src/038-unions-and-narrowing/044-narrowing-with-boolean-wont-work.explainer.ts diff --git a/src/038-unions-and-narrowing/044-throwing-errors-to-narrow.problem.ts b/src/038-unions-and-narrowing/045-throwing-errors-to-narrow.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/044-throwing-errors-to-narrow.problem.ts rename to src/038-unions-and-narrowing/045-throwing-errors-to-narrow.problem.ts diff --git a/src/038-unions-and-narrowing/044-throwing-errors-to-narrow.solution.ts b/src/038-unions-and-narrowing/045-throwing-errors-to-narrow.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/044-throwing-errors-to-narrow.solution.ts rename to src/038-unions-and-narrowing/045-throwing-errors-to-narrow.solution.ts diff --git a/src/038-unions-and-narrowing/045-narrowing-with-instanceof-statements.problem.ts b/src/038-unions-and-narrowing/046-narrowing-with-instanceof-statements.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/045-narrowing-with-instanceof-statements.problem.ts rename to src/038-unions-and-narrowing/046-narrowing-with-instanceof-statements.problem.ts diff --git a/src/038-unions-and-narrowing/045-narrowing-with-instanceof-statements.solution.ts b/src/038-unions-and-narrowing/046-narrowing-with-instanceof-statements.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/045-narrowing-with-instanceof-statements.solution.ts rename to src/038-unions-and-narrowing/046-narrowing-with-instanceof-statements.solution.ts diff --git a/src/038-unions-and-narrowing/046-narrowing-with-in-statements.problem.ts b/src/038-unions-and-narrowing/047-narrowing-with-in-statements.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/046-narrowing-with-in-statements.problem.ts rename to src/038-unions-and-narrowing/047-narrowing-with-in-statements.problem.ts diff --git a/src/038-unions-and-narrowing/046-narrowing-with-in-statements.solution.ts b/src/038-unions-and-narrowing/047-narrowing-with-in-statements.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/046-narrowing-with-in-statements.solution.ts rename to src/038-unions-and-narrowing/047-narrowing-with-in-statements.solution.ts diff --git a/src/038-unions-and-narrowing/047-narrowing-unknown-to-a-value.problem.ts b/src/038-unions-and-narrowing/048-narrowing-unknown-to-a-value.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/047-narrowing-unknown-to-a-value.problem.ts rename to src/038-unions-and-narrowing/048-narrowing-unknown-to-a-value.problem.ts diff --git a/src/038-unions-and-narrowing/047-narrowing-unknown-to-a-value.solution.ts b/src/038-unions-and-narrowing/048-narrowing-unknown-to-a-value.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/047-narrowing-unknown-to-a-value.solution.ts rename to src/038-unions-and-narrowing/048-narrowing-unknown-to-a-value.solution.ts diff --git a/src/038-unions-and-narrowing/048-narrowing-with-ternaries.problem.ts b/src/038-unions-and-narrowing/049-narrowing-with-ternaries.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/048-narrowing-with-ternaries.problem.ts rename to src/038-unions-and-narrowing/049-narrowing-with-ternaries.problem.ts diff --git a/src/038-unions-and-narrowing/048-narrowing-with-ternaries.solution.ts b/src/038-unions-and-narrowing/049-narrowing-with-ternaries.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/048-narrowing-with-ternaries.solution.ts rename to src/038-unions-and-narrowing/049-narrowing-with-ternaries.solution.ts diff --git a/src/038-unions-and-narrowing/049-narrowing-with-nullish-coalescing.problem.ts b/src/038-unions-and-narrowing/050-narrowing-with-nullish-coalescing.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/049-narrowing-with-nullish-coalescing.problem.ts rename to src/038-unions-and-narrowing/050-narrowing-with-nullish-coalescing.problem.ts diff --git a/src/038-unions-and-narrowing/049-narrowing-with-nullish-coalescing.solution.ts b/src/038-unions-and-narrowing/050-narrowing-with-nullish-coalescing.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/049-narrowing-with-nullish-coalescing.solution.ts rename to src/038-unions-and-narrowing/050-narrowing-with-nullish-coalescing.solution.ts diff --git a/src/038-unions-and-narrowing/050-intro-to-discriminated-unions.problem.ts b/src/038-unions-and-narrowing/051-intro-to-discriminated-unions.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/050-intro-to-discriminated-unions.problem.ts rename to src/038-unions-and-narrowing/051-intro-to-discriminated-unions.problem.ts diff --git a/src/038-unions-and-narrowing/050-intro-to-discriminated-unions.solution.ts b/src/038-unions-and-narrowing/051-intro-to-discriminated-unions.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/050-intro-to-discriminated-unions.solution.ts rename to src/038-unions-and-narrowing/051-intro-to-discriminated-unions.solution.ts diff --git a/src/038-unions-and-narrowing/051-destructuring-a-discriminated-union.problem.ts b/src/038-unions-and-narrowing/052-destructuring-a-discriminated-union.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/051-destructuring-a-discriminated-union.problem.ts rename to src/038-unions-and-narrowing/052-destructuring-a-discriminated-union.problem.ts diff --git a/src/038-unions-and-narrowing/051-destructuring-a-discriminated-union.solution.ts b/src/038-unions-and-narrowing/052-destructuring-a-discriminated-union.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/051-destructuring-a-discriminated-union.solution.ts rename to src/038-unions-and-narrowing/052-destructuring-a-discriminated-union.solution.ts diff --git a/src/038-unions-and-narrowing/052-narrowing-a-discriminated-union-with-a-switch-statement.problem.ts b/src/038-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/052-narrowing-a-discriminated-union-with-a-switch-statement.problem.ts rename to src/038-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.problem.ts diff --git a/src/038-unions-and-narrowing/052-narrowing-a-discriminated-union-with-a-switch-statement.solution.ts b/src/038-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/052-narrowing-a-discriminated-union-with-a-switch-statement.solution.ts rename to src/038-unions-and-narrowing/053-narrowing-a-discriminated-union-with-a-switch-statement.solution.ts diff --git a/src/038-unions-and-narrowing/053-narrowing-with-switch-true.explainer.ts b/src/038-unions-and-narrowing/054-narrowing-with-switch-true.explainer.ts similarity index 100% rename from src/038-unions-and-narrowing/053-narrowing-with-switch-true.explainer.ts rename to src/038-unions-and-narrowing/054-narrowing-with-switch-true.explainer.ts diff --git a/src/038-unions-and-narrowing/054-destructuring-a-discriminated-tuple.problem.ts b/src/038-unions-and-narrowing/055-destructuring-a-discriminated-tuple.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/054-destructuring-a-discriminated-tuple.problem.ts rename to src/038-unions-and-narrowing/055-destructuring-a-discriminated-tuple.problem.ts diff --git a/src/038-unions-and-narrowing/054-destructuring-a-discriminated-tuple.solution.ts b/src/038-unions-and-narrowing/055-destructuring-a-discriminated-tuple.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/054-destructuring-a-discriminated-tuple.solution.ts rename to src/038-unions-and-narrowing/055-destructuring-a-discriminated-tuple.solution.ts diff --git a/src/038-unions-and-narrowing/055-discriminated-booleans.problem.ts b/src/038-unions-and-narrowing/056-discriminated-booleans.problem.ts similarity index 100% rename from src/038-unions-and-narrowing/055-discriminated-booleans.problem.ts rename to src/038-unions-and-narrowing/056-discriminated-booleans.problem.ts diff --git a/src/038-unions-and-narrowing/055-discriminated-booleans.solution.ts b/src/038-unions-and-narrowing/056-discriminated-booleans.solution.ts similarity index 100% rename from src/038-unions-and-narrowing/055-discriminated-booleans.solution.ts rename to src/038-unions-and-narrowing/056-discriminated-booleans.solution.ts