cf.completefrontend

Predict the typesEasy

What does TypeScript narrow these typeof and truthiness checks to, and what does the code log?

Name the type each ^? line points at, every error TypeScript reports, and what the last line logs when you run the code anyway, with its types removed.

What does TypeScript report here?
function size(value: string | string[] | null) {  if (typeof value === "object") {    value;//  ^?    return value.length;  }  return value.length;  //     ^?} function label(count: number | undefined) {  if (count) {    return `${count} items`;  }  return count;  //     ^?} console.log(label(0), label(3));

Work it out first: the compiler shows every error and type.

The answer

Work out every error TypeScript reports and every type it shows, line by line. Then check.

Checking your sign-in…