Skip to content

Commit 256a509

Browse files
committed
👍 Add isSymbol
1 parent 0e9677b commit 256a509

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

is.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ export function isNullish(x: unknown): x is null | undefined {
205205
return x == null;
206206
}
207207

208+
/**
209+
* Return `true` if the type of `x` is `symbol`.
210+
*/
211+
export function isSymbol(x: unknown): x is symbol {
212+
return typeof x === "symbol";
213+
}
214+
208215
export type OneOf<T> = T extends (infer U)[]
209216
? T extends Predicate<infer U>[] ? U : T
210217
: T;
@@ -245,5 +252,6 @@ export default {
245252
Null: isNull,
246253
Undefined: isUndefined,
247254
Nullish: isNullish,
255+
Symbol: isSymbol,
248256
OneOf: isOneOf,
249257
};

is_test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import is, {
1717
isRecord,
1818
isRecordOf,
1919
isString,
20+
isSymbol,
2021
isTupleOf,
2122
isUndefined,
2223
Predicate,
@@ -32,6 +33,7 @@ const examples = {
3233
function: [function () {}],
3334
null: [null],
3435
undefined: [undefined],
36+
symbol: [Symbol("a"), Symbol("b"), Symbol("c")],
3537
};
3638

3739
function stringify(x: unknown): string {
@@ -240,6 +242,10 @@ Deno.test("isNullish", async (t) => {
240242
await testWithExamples(t, isNullish, ["null", "undefined"]);
241243
});
242244

245+
Deno.test("isSymbol", async (t) => {
246+
await testWithExamples(t, isSymbol, ["symbol"]);
247+
});
248+
243249
Deno.test("isOneOf<T>", async (t) => {
244250
await t.step("returns proper type predicate", () => {
245251
const preds = [isNumber, isString, isBoolean];

0 commit comments

Comments
 (0)