Type guard that checks if a value is a string.
Type Narrowing Behavior:
unknown
string
true
The value to check
true if u is a string, false otherwise. When true, TypeScript narrows the type to string.
u
false
const values: unknown[] = ['Ada', 42, 'Lovelace'];const strings = values.filter(isString);assert.deepStrictEqual(strings, ['Ada', 'Lovelace']); Copy
const values: unknown[] = ['Ada', 42, 'Lovelace'];const strings = values.filter(isString);assert.deepStrictEqual(strings, ['Ada', 'Lovelace']);
Type guard that checks if a value is a string.
Type Narrowing Behavior:
unknown
tostring
whentrue