isString
Checks whether a value is a primitive string. This helper never throws and never mutates input. It performs a strict typeof check and does not coerce values.
Signature
function isString(value: unknown): value is string
Parameters
| Name | Data type | Description |
|---|---|---|
| value | unknown |
The value to check. Must be a string (primitive string) to return true. |
Returns
trueif the value is a primitive string.falseotherwise.
Examples
isString("hello") // true
isString("") // true
isString(123) // false
isString(null) // false
isString(undefined) // false
isString({}) // false
isString([]) // false
isString(new String("hello")) // false
Notes
- This helper does not trim or modify the value.
- This helper returns
falsefor String objects (for example,new String("x")). - Use
isNonEmptyStringif you need to ensure the string is not empty. - Use
normalizeStringif you need to convert values into strings.