Function assertIsString

Checks if the provided value is a string.

Error if the value is not a string.

const fn = (x: unknown) => {
assertIsString(x); // throws an error if x is not a string
return x; // x has inferred type string
};
  • Parameters

    • x: unknown

      The value to check.

    Returns asserts x is string