Skip to content

Commit 76d7609

Browse files
author
Kubit
committed
Improve documentation of isStringTypeOf
1 parent 7b6c8bd commit 76d7609

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
export const isStringTypeOf = (value: unknown): boolean => {
1+
/**
2+
* @description - Typescript validator to assert if a value is `string` type.
3+
*
4+
* @example
5+
*
6+
* let foo: number | string = 0
7+
*
8+
* if(Math.random() < 0.5){
9+
* foo = 'bar'
10+
* }
11+
*
12+
* if(isStringTypeOf(foo)) {
13+
* // We asserted the value is actually an string!
14+
* console.log("foo length is: " + foo.length) // foo length is 3
15+
* }
16+
*/
17+
export const isStringTypeOf = (value: unknown): value is string => {
218
return typeof value === 'string';
319
};

0 commit comments

Comments
 (0)