cf.completefrontend

Predict the typesHard

Which of these indirect checks does TypeScript still narrow on?

None of the checks is written directly in the if or switch that uses it. Name the type each ^? line points at, and say whether TypeScript reports any errors.

What does TypeScript report here?
type Result = { ok: true; value: number } | { ok: false; value: string }; function show(result: Result, input: string | number) {  const isText = typeof input === "string";  if (isText) {    input;//  ^?  }   let isTextLater = typeof input === "string";  if (isTextLater) {    input;//  ^?  }   const { ok, value } = result;  if (ok) {    value;//  ^?  }   switch (true) {    case typeof input === "number":      input;//    ^?  }}

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…