-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3cf1af
commit 7018934
Showing
7 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
30 changes: 30 additions & 0 deletions
30
src/040-deriving-types-from-values/128-classes-cross-value-and-type-world.problem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/040-deriving-types-from-values/128-classes-cross-value-and-type-world.solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.explainer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Equal<typeof node, CanvasNode>>; |
Empty file removed
0
src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.problem.ts
Empty file.
Empty file removed
0
src/040-deriving-types-from-values/129-this-crosses-value-and-type-world.solution.ts
Empty file.