How string-ts provides strongly-typed string transformations
mainStandard JavaScript string methods (like .replace()) only operate at runtime, causing TypeScript to lose specific literal type information and fall back to the generic string type.
string-ts provides utility functions that perform the same operations at runtime while preserving literal types (and unions of literals) at the type level. This allows for better static analysis and prevents errors that would otherwise only be caught at runtime.
import { replace } from 'string-ts'
const str = 'hello-world'
const result = replace(str, '-', ' ')
// ^ 'hello world'