File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff 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+
208215export 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} ;
Original file line number Diff line number Diff 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
3739function 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+
243249Deno . test ( "isOneOf<T>" , async ( t ) => {
244250 await t . step ( "returns proper type predicate" , ( ) => {
245251 const preds = [ isNumber , isString , isBoolean ] ;
You can’t perform that action at this time.
0 commit comments