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">72type (sp>53 valuAE=<==sp ansty="le--0:#D6DEEB;--1:#403F">5==sp><3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dstrn1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)1"sp>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0processStri sp>53(value {d><);d ivclassNa="meec-li">5);d><3}d ivclassNa="meco"><}d>}d>3}d>AE53< (sp ansty="le--0:#7FDBCA;--1:#096E">72type (sp>53 callbacAE!<==sp ansty="le--0:#D6DEEB;--1:#403F">5==sp><3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dfucnti1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)1"sp>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEthr sp>5<3 sp ansty="le--0:#7FDBCA;--1:#096E">72n3 sp>5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Err3 sp>5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4DInvalid callba1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp> {d><);d ivclassNa="meec-li">5);d><3}d ivclassNa="meco"><}d>}d>3}d>AE53< (sp ansty="le--0:#7FDBCA;--1:#096E">72type (sp>53 datAE<==sp ansty="le--0:#D6DEEB;--1:#403F">5==sp><3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dundefim1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)1"sp>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0initiali sp>53( {d><);d ivclassNa="meec-li">5);d><3}d ivclassNa="meco"><}d>}d>3}d>AE53< (sp ansty="le--0:#7FDBCA;--1:#096E">72type (sp>53 counAE=<==sp ansty="le--0:#D6DEEB;--1:#403F">5==sp><3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dnunb1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)1"sp>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0calcula sp>53(count {d><);d ivclassNa="meec-li">5);d><3}d ivclassNa="meco"><}d>}d>3}d> 443F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E72ty53 (>3F53 va44A31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dst111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5111"><3) {divclass="Nameec-">de61B0processSt3F53(val3) >3<);>);><}di vdivclass="Nameexpressive-">443F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E72ty53 (>3F53 callb44A31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dfunc111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5111"><3) {divclass="Nameec-">de44AEt36E7<2new spans="tyle--0:#D6DEEB;--1:#40">32new>61B0E31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DInvalid call111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111">3) ><53) ;divclass="Nameec-">353)><);>);>}di><}di vdivclass="Nameexpressive-">443F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E72ty53 (>3F53 d4431<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dundef111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5111"><3) {divclass="Nameec-">de61B0initia3F53) ><3() ;divclass="Nameec-">33()><);>);>}di><}di vdivclass="Nameexpressive-">443F<53 ( spans="tyle--0:#7FDBCA;--1:#09">6E72ty53 (>3F53 co44A31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dnu111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F5111"><3) {divclass="Nameec-">de61B0calcu3F53(cou3) >3<);>);>}di>
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.