0 of 6 problems solved0%
5 of 6

Build a Custom Guard

A custom type guard lets you express your own check and teach it to TypeScript. Use the value is Type return type to narrow at call sites. Keep the runtime check simple and aligned with the type you claim.

function isNum(x: unknown): x is number {
  return typeof x === "number";
}

Filter an array of unknown values down to non-empty strings, then join them for display.

Your Task

Create a guard and use it to filter and join values.

  • Write function isNonEmptyString(v: unknown): v is string that returns true only for strings with v.trim().length > 0.
  • Write function joinNonEmpty(parts: unknown[]): string.
  • joinNonEmpty should keep only values where isNonEmptyString returns true, then trim() each and join with ','.
  • Do not mutate the input array.