diff --git a/src/075-designing-your-types/177-domain-modelling-in-typescript.explainer.ts b/src/075-designing-your-types/177-domain-modelling-in-typescript.explainer.ts new file mode 100644 index 0000000..2676af5 --- /dev/null +++ b/src/075-designing-your-types/177-domain-modelling-in-typescript.explainer.ts @@ -0,0 +1,7 @@ +// Modelling your domain in TypeScript + +// Think of the entities in your domain as individual types + +// Compose those types together + +// Think about types as containers for other types diff --git a/src/075-designing-your-types/177-domain-modelling-in-typescript.problem.ts b/src/075-designing-your-types/177-domain-modelling-in-typescript.problem.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/075-designing-your-types/177-domain-modelling-in-typescript.solution.ts b/src/075-designing-your-types/177-domain-modelling-in-typescript.solution.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/075-designing-your-types/179-multiple-type-parameters.problem.ts b/src/075-designing-your-types/179-multiple-type-parameters.problem.ts index e69de29..d428d1b 100644 --- a/src/075-designing-your-types/179-multiple-type-parameters.problem.ts +++ b/src/075-designing-your-types/179-multiple-type-parameters.problem.ts @@ -0,0 +1,9 @@ +type PromiseFunc = (input: any) => Promise; + +type Example1 = PromiseFunc; + +type test1 = Expect Promise>>; + +type Example2 = PromiseFunc; + +type test2 = Expect Promise>>; diff --git a/src/075-designing-your-types/179-multiple-type-parameters.solution.ts b/src/075-designing-your-types/179-multiple-type-parameters.solution.ts index e69de29..d5c04ab 100644 --- a/src/075-designing-your-types/179-multiple-type-parameters.solution.ts +++ b/src/075-designing-your-types/179-multiple-type-parameters.solution.ts @@ -0,0 +1,9 @@ +type PromiseFunc = (input: Input) => Promise; + +type Example1 = PromiseFunc; + +type test1 = Expect Promise>>; + +type Example2 = PromiseFunc; + +type test2 = Expect Promise>>; diff --git a/src/075-designing-your-types/182-type-helper-constraints.problem.ts b/src/075-designing-your-types/182-type-helper-constraints.problem.ts index e69de29..0a07072 100644 --- a/src/075-designing-your-types/182-type-helper-constraints.problem.ts +++ b/src/075-designing-your-types/182-type-helper-constraints.problem.ts @@ -0,0 +1,20 @@ +type Result = + | { + success: true; + data: TResult; + } + | { + success: false; + error: TError; + }; + +type BadExample = Result< + { id: string }, + // @ts-expect-error Should be an object with a message property + string +>; + +type GoodExample = Result<{ id: string }, TypeError>; +type GoodExample2 = Result<{ id: string }, { message: string; code: number }>; +type GoodExample3 = Result<{ id: string }, { message: string }>; +type GoodExample4 = Result<{ id: string }>; diff --git a/src/075-designing-your-types/182-type-helper-constraints.solution.ts b/src/075-designing-your-types/182-type-helper-constraints.solution.ts index e69de29..d19d04c 100644 --- a/src/075-designing-your-types/182-type-helper-constraints.solution.ts +++ b/src/075-designing-your-types/182-type-helper-constraints.solution.ts @@ -0,0 +1,20 @@ +type Result = + | { + success: true; + data: TResult; + } + | { + success: false; + error: TError; + }; + +type BadExample = Result< + { id: string }, + // @ts-expect-error Should be an object with a message property + string +>; + +type GoodExample = Result<{ id: string }, TypeError>; +type GoodExample2 = Result<{ id: string }, { message: string; code: number }>; +type GoodExample3 = Result<{ id: string }, { message: string }>; +type GoodExample4 = Result<{ id: string }>; diff --git a/src/075-designing-your-types/183-tighter-version-of-omit.problem.ts b/src/075-designing-your-types/183-tighter-version-of-omit.problem.ts index e69de29..d8d2438 100644 --- a/src/075-designing-your-types/183-tighter-version-of-omit.problem.ts +++ b/src/075-designing-your-types/183-tighter-version-of-omit.problem.ts @@ -0,0 +1,15 @@ +type StrictOmit = Omit; + +type ShouldFail = StrictOmit< + { a: string }, + // @ts-expect-error + "b" +>; + +type tests = [ + Expect, { a: string }>>, + Expect, {}>>, + Expect< + Equal, { a: string; b: number }> + >, +]; diff --git a/src/075-designing-your-types/183-tighter-version-of-omit.solution.ts b/src/075-designing-your-types/183-tighter-version-of-omit.solution.ts index e69de29..a585492 100644 --- a/src/075-designing-your-types/183-tighter-version-of-omit.solution.ts +++ b/src/075-designing-your-types/183-tighter-version-of-omit.solution.ts @@ -0,0 +1,15 @@ +type StrictOmit = Omit; + +type ShouldFail = StrictOmit< + { a: string }, + // @ts-expect-error + "b" +>; + +type tests = [ + Expect, { a: string }>>, + Expect, {}>>, + Expect< + Equal, { a: string; b: number }> + >, +];