0
# Basic Type Checking
1
2
Fundamental type checking functions for JavaScript primitives and basic types. All functions are TypeScript type guards that provide automatic type narrowing.
3
4
## Capabilities
5
6
### String Type Checking
7
8
Returns whether the payload is a string.
9
10
```typescript { .api }
11
/**
12
* Returns whether the payload is a string
13
* @param payload - Value to check
14
* @returns Type guard indicating if payload is string
15
*/
16
function isString(payload: unknown): payload is string;
17
```
18
19
**Usage Examples:**
20
21
```typescript
22
import { isString } from "is-what";
23
24
if (isString("hello")) {
25
// TypeScript knows this is a string
26
console.log("hello".toUpperCase()); // "HELLO"
27
}
28
29
isString("text"); // true
30
isString(123); // false
31
isString(new String("text")); // false (String object, not primitive)
32
```
33
34
### Number Type Checking
35
36
Returns whether the payload is a number (but not NaN). This function specifically excludes NaN values.
37
38
```typescript { .api }
39
/**
40
* Returns whether the payload is a number (but not NaN)
41
* This will return false for NaN
42
* @param payload - Value to check
43
* @returns Type guard indicating if payload is number (excluding NaN)
44
*/
45
function isNumber(payload: unknown): payload is number;
46
```
47
48
**Usage Examples:**
49
50
```typescript
51
import { isNumber } from "is-what";
52
53
isNumber(42); // true
54
isNumber(3.14); // true
55
isNumber(NaN); // false (special case!)
56
isNumber("123"); // false
57
isNumber(new Number(123)); // false (Number object, not primitive)
58
59
if (isNumber(value)) {
60
// Safe to use number methods
61
console.log(value.toFixed(2));
62
}
63
```
64
65
### Boolean Type Checking
66
67
Returns whether the payload is a boolean.
68
69
```typescript { .api }
70
/**
71
* Returns whether the payload is a boolean
72
* @param payload - Value to check
73
* @returns Type guard indicating if payload is boolean
74
*/
75
function isBoolean(payload: unknown): payload is boolean;
76
```
77
78
**Usage Examples:**
79
80
```typescript
81
import { isBoolean } from "is-what";
82
83
isBoolean(true); // true
84
isBoolean(false); // true
85
isBoolean("true"); // false
86
isBoolean(1); // false
87
isBoolean(new Boolean(true)); // false (Boolean object, not primitive)
88
```
89
90
### BigInt Type Checking
91
92
Returns whether the payload is a bigint.
93
94
```typescript { .api }
95
/**
96
* Returns whether the payload is a bigint
97
* @param payload - Value to check
98
* @returns Type guard indicating if payload is bigint
99
*/
100
function isBigInt(payload: unknown): payload is bigint;
101
```
102
103
**Usage Examples:**
104
105
```typescript
106
import { isBigInt } from "is-what";
107
108
isBigInt(123n); // true
109
isBigInt(BigInt(123)); // true
110
isBigInt(123); // false
111
isBigInt("123n"); // false
112
```
113
114
### Symbol Type Checking
115
116
Returns whether the payload is a symbol.
117
118
```typescript { .api }
119
/**
120
* Returns whether the payload is a symbol
121
* @param payload - Value to check
122
* @returns Type guard indicating if payload is symbol
123
*/
124
function isSymbol(payload: unknown): payload is symbol;
125
```
126
127
**Usage Examples:**
128
129
```typescript
130
import { isSymbol } from "is-what";
131
132
isSymbol(Symbol("test")); // true
133
isSymbol(Symbol.iterator); // true
134
isSymbol("symbol"); // false
135
isSymbol(123); // false
136
```
137
138
### Null Type Checking
139
140
Returns whether the payload is null.
141
142
```typescript { .api }
143
/**
144
* Returns whether the payload is null
145
* @param payload - Value to check
146
* @returns Type guard indicating if payload is null
147
*/
148
function isNull(payload: unknown): payload is null;
149
```
150
151
**Usage Examples:**
152
153
```typescript
154
import { isNull } from "is-what";
155
156
isNull(null); // true
157
isNull(undefined); // false
158
isNull(0); // false
159
isNull(""); // false
160
```
161
162
### Undefined Type Checking
163
164
Returns whether the payload is undefined.
165
166
```typescript { .api }
167
/**
168
* Returns whether the payload is undefined
169
* @param payload - Value to check
170
* @returns Type guard indicating if payload is undefined
171
*/
172
function isUndefined(payload: unknown): payload is undefined;
173
```
174
175
**Usage Examples:**
176
177
```typescript
178
import { isUndefined } from "is-what";
179
180
isUndefined(undefined); // true
181
isUndefined(null); // false
182
isUndefined(0); // false
183
isUndefined(""); // false
184
185
let x;
186
isUndefined(x); // true
187
```