es-toolkit/docs/reference/predicate/isString.md
uussong b11fd69e17
feat(isString): Add isString function (#379)
* feat(isString): Add isString function

* test(isString): Add isString tests

* docs(isString): Add and improve docs for isString

* Update src/compat/predicate/isString.spec.ts

* Update src/compat/predicate/isString.spec.ts

* Update src/predicate/index.ts

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
2024-08-15 11:06:47 +09:00

619 B

isString

Checks if the given value is a string.

This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to string.

Signature

function isString(value: unknown): value is string;

Parameters

  • value(unknown): The value to test if it is string.

Returns

  • (x is string): True if the value is a string, otherwise false.

Examples

const value1 = 'abc';
const value2 = 123;
const value3 = true;

console.log(isString(value1)); // true
console.log(isString(value2)); // false
console.log(isString(value3)); // false