Skip to content

Latest commit

 

History

History
36 lines (19 loc) · 692 Bytes

prefer-lodash-typecheck.md

File metadata and controls

36 lines (19 loc) · 692 Bytes

Prefer Lodash typecheck

Getting the specific type of a variable or expression can be done with typeof or instanceof. However, it's often more expressive to use the Lodash equivalent function

Rule Details

This rule takes no arguments.

The following patterns are considered warnings:

if (typeof a === 'number') {
  // ...
}

var isNotString = typeof b !== 'string';

var isArray = a instanceof Array;

The following patterns are not considered warnings:

var areSameType = typeof a === typeof b;
 
var isCar = truck instanceof Car; 

When Not To Use It

If you do not want to enforce using Lodash methods for type checks, you should not use this rule.