diff --git a/src/040-deriving-types-from-values/128-classes-and-enums-cross-value-and-type-world.problem.ts b/src/040-deriving-types-from-values/128-classes-and-enums-cross-value-and-type-world.problem.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/040-deriving-types-from-values/128-classes-and-enums-cross-value-and-type-world.solution.ts b/src/040-deriving-types-from-values/128-classes-and-enums-cross-value-and-type-world.solution.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/040-deriving-types-from-values/128-classes-cross-value-and-type-world.problem.ts b/src/040-deriving-types-from-values/128-classes-cross-value-and-type-world.problem.ts new file mode 100644 index 0000000..2a6d592 --- /dev/null +++ b/src/040-deriving-types-from-values/128-classes-cross-value-and-type-world.problem.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "vitest"; + +class CanvasNode { + x = 0; + y = 0; + + move(x: number, y: number) { + this.x = x; + this.y = y; + } +} + +const positionFromCanvasNode = (node) => { + return { + x: node.x, + y: node.y, + }; +}; + +describe("positionFromCanvasNode", () => { + it("Should return the position of the node", () => { + const canvasNode = new CanvasNode(); + + expect(positionFromCanvasNode(canvasNode)).toEqual({ x: 0, y: 0 }); + + canvasNode.move(10, 20); + + expect(positionFromCanvasNode(canvasNode)).toEqual({ x: 10, y: 20 }); + }); +}); diff --git a/src/040-deriving-types-from-values/128-classes-cross-value-and-type-world.solution.ts b/src/040-deriving-types-from-values/128-classes-cross-value-and-type-world.solution.ts new file mode 100644 index 0000000..cb9a889 --- /dev/null +++ b/src/040-deriving-types-from-values/128-classes-cross-value-and-type-world.solution.ts @@ -0,0 +1,31 @@ +import { describe, expect, it } from "vitest"; + +class CanvasNode { + x = 0; + y = 0; + + move(x: number, y: number) { + this.x = x; + this.y = y; + } +} + +// Look at typeof CanvasNode +const positionFromCanvasNode = (node: CanvasNode) => { + return { + x: node.x, + y: node.y, + }; +}; + +describe("positionFromCanvasNode", () => { + it("Should return the position of the node", () => { + const canvasNode = new CanvasNode(); + + expect(positionFromCanvasNode(canvasNode)).toEqual({ x: 0, y: 0 }); + + canvasNode.move(10, 20); + + expect(positionFromCanvasNode(canvasNode)).toEqual({ x: 10, y: 20 }); + }); +}); diff --git a/src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.explainer.ts b/src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.explainer.ts new file mode 100644 index 0000000..4430dba --- /dev/null +++ b/src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.explainer.ts @@ -0,0 +1,19 @@ +class CanvasNode { + x: number; + y: number; + + constructor(x: number, y: number) { + this.x = x; + this.y = y; + } + + move(x: number, y: number): this { + this.x += x; + this.y += y; + return this; + } +} + +const node = new CanvasNode(0, 0).move(10, 20).move(30, 40); + +type test = Expect>; diff --git a/src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.problem.ts b/src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.problem.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.solution.ts b/src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.solution.ts deleted file mode 100644 index e69de29..0000000