From 8e3fdbb8b850fc13fb647312262125cf81910b3f Mon Sep 17 00:00:00 2001 From: Jason Lotz Date: Sun, 12 Nov 2023 13:45:24 -0500 Subject: [PATCH] Update for item #8. --- .../type-value-space-10.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/samples/ch02-types/item-08-type-value-space/type-value-space-10.ts b/samples/ch02-types/item-08-type-value-space/type-value-space-10.ts index 12e28d5..239d13d 100644 --- a/samples/ch02-types/item-08-type-value-space/type-value-space-10.ts +++ b/samples/ch02-types/item-08-type-value-space/type-value-space-10.ts @@ -2,7 +2,7 @@ interface Person { first: string; last: string; } -const p: Person = { first: 'Jane', last: 'Jacobs' }; +const p: Person = { first: "Jane", last: "Jacobs" }; // - --------------------------------- Values // ------ Type function email(p: Person, subject: string, body: string): Response { @@ -14,16 +14,19 @@ function email(p: Person, subject: string, body: string): Response { } class Cylinder { - radius=1; - height=1; + radius = 1; + height = 1; } function calculateVolume(shape: unknown) { if (shape instanceof Cylinder) { - shape // OK, type is Cylinder - shape.radius // OK, type is number + shape; // OK, type is Cylinder + shape.radius; // OK, type is number } } -const v = typeof Cylinder; // Value is "function" -type T = typeof Cylinder; // Type is typeof Cylinder -type C = InstanceType; // Type is Cylinder +const v = typeof Cylinder; // Value is "function" +type T = typeof Cylinder; // Type is typeof Cylinder +type C = InstanceType; // Type is Cylinder + +const ok: C = new Cylinder(); // OK, type is Cylinder +const error: T = new Cylinder(); // Error, type is typeof Cylinder