This page is not yet available in Spanish. We are working on its translation. If you have any questions or feedback about our current translation project, feel free to reach out to us!
Metadata
ID:javascript-best-practices/valid-typeof
Language: JavaScript
Severity: Warning
Category: Error Prone
Description
Always compare typeof expressions against strings and make sure they are the correct values.
typeoffoo==='string';typeoffoo==='object';typeoffoo==='function';typeoffoo==='undefined';typeoffoo==='boolean';typeoffoo==='number';typeoffoo==='bigint';'string'===typeoffoo;'object'===typeoffoo;'function'===typeoffoo;'undefined'===typeoffoo;'boolean'===typeoffoo;'number'===typeoffoo;typeoffoo===typeofbar;typeoffoo===baz;typeoffoo!==someType;typeofbar!=someType;someType===typeofbar;someType==typeofbar;typeoffoo=='string';typeof(foo)==='string';typeof(foo)!=='string';typeof(foo)=='string';typeof(foo)!='string';varoddUse=typeoffoo+'thing';// since we don't have optios we are enforcing to always compare agaisnt strings
// function f(undefined) { typeof x === undefined };
typeoffoo==='number';typeoffoo==="number";varbaz=typeoffoo+'thing';typeoffoo===typeofbar;typeoffoo===`string`;`object`===typeoffoo;// not supported by this rule, we cannot pretend that somethingElse will complete 'string'
// typeof foo === `str${somethingElse}`;
Integraciones sin problemas. Prueba Datadog Code Security
Datadog Code Security
Prueba esta regla y analiza tu código con Datadog Code Security
Cómo usar esta regla
1
2
rulesets:- javascript-best-practices # Rules to enforce JavaScript best practices.
Crea un static-analysis.datadog.yml con el contenido anterior en la raíz de tu repositorio
Utiliza nuestros complementos del IDE gratuitos o añade análisis de Code Security a tus pipelines de CI.