Hyperlinkv0.8.0-beta.28

Inspectable

Inspectable.toStringUnknownconsteffect/Inspectable.ts:185
(u: unknown, whitespace?: number | string | undefined): string

Converts an unknown value to a string for diagnostics.

When to use

Use to produce a diagnostic string from a value whose runtime type is unknown.

Details

Strings are returned unchanged. Objects are formatted as JSON using the provided whitespace setting when possible, and values that cannot be formatted are converted with String.

converting
export const toStringUnknown = (u: unknown, whitespace: number | string | undefined = 2): string => {
  if (typeof u === "string") {
    return u
  }
  try {
    return typeof u === "object" ? formatJson(u, { space: whitespace }) : String(u)
  } catch {
    return String(u)
  }
}