We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7b6c8bd commit 76d7609Copy full SHA for 76d7609
src/utils/isStringTypeOf/isStringTypeOf.ts
@@ -1,3 +1,19 @@
1
-export const isStringTypeOf = (value: unknown): boolean => {
+/**
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 => {
18
return typeof value === 'string';
19
};
0 commit comments