Skip to content

typeofComparisons

Reports typeof expressions that compare impossible string literals.

✅ This rule is included in the ts javascript presets.

The typeof operator in JavaScript returns one of a specific set of string values: "bigint", "boolean", "function", "number", "object", "string", "symbol", or "undefined". Comparing the result of typeof to any other string literal is usually a typo and the comparison will never be true. This rule enforces that typeof expressions are only compared to valid string literals.

AE53< (sp ansty="le--0:#7FDBCA;--1:#096E">72type53 valuAE=<==sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dstrn1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0processStri53(value<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AE53< (sp ansty="le--0:#7FDBCA;--1:#096E">72type53 callbacAE!<==sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dfucnti1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEthr5<3 sp ansty="le--0:#7FDBCA;--1:#096E">72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Err5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DInvalid callba1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AE53< (sp ansty="le--0:#7FDBCA;--1:#096E">72type53 datAE<==sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dundefim1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0initiali53(<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AE53< (sp ansty="le--0:#7FDBCA;--1:#096E">72type53 counAE=<==sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dnunb1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0calcula53(count<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
443F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E72ty3F53 va44A31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dst1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5<3) {divclass="Nameec-">de61B0processSt3F53(val3<);><}di vdivclass="Nameexpressive-">443F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E72ty3F53 callb44A31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dfunc1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5<3) {divclass="Nameec-">de44AEt36E7<2new spans="tyle--0:#D6DEEB;--1:#40">361B0E31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DInvalid call1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Nameec-">3<);><}di vdivclass="Nameexpressive-">443F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E72ty3F53 d4431<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dundef1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5<3) {divclass="Nameec-">de61B0initia3F5<3() ;divclass="Nameec-">3<);><}di vdivclass="Nameexpressive-">443F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E72ty3F53 co44A31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dnu1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5<3) {divclass="Nameec-">de61B0calcu3F53(cou3<);>

This rule is not configurable.

If your project is a rare one that operates on non-standard objects, such as ancient versions of obscure browsers, this rule might not benefit you. For all other projects, using either this rule or a full type-checker should always be done.