Docs (4.0.0)
Text formatting

type StringConvertible

String type or object that has a toString method.

type StringConvertible = string | {
    toString(): string;
}

Description

This type is often used where an argument is expected that can be converted to a string (i.e. using String(...)), hence doesn’t necessarily need to be a string type itself. This includes strings and numbers, but also all objects that have a toString method — notably, object LazyString objects, the result of strf().

Example

// A function that uses a string
function useString(s: StringConvertible) {
  // ... do something with String(s) or use as string
  console.log("Foo: " + s);
}

useString("abc");
useString(123);
useString(strf("%.2f", 123));

Static Members

Related