Skip to content

Commit

Permalink
Update for item danvk#8.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlotz committed Nov 15, 2023
1 parent 846e952 commit 11d6db3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions samples/ch02-types/item-08-type-value-space/type-value-space-10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<typeof Cylinder>; // Type is Cylinder
const v = typeof Cylinder; // Value is "function"
type T = typeof Cylinder; // Type is typeof Cylinder
type C = InstanceType<typeof Cylinder>; // Type is Cylinder

const ok: C = new Cylinder(); // OK, type is Cylinder
const error: T = new Cylinder(); // Error, type is typeof Cylinder

0 comments on commit 11d6db3

Please sign in to comment.