This product is not supported for your selected Datadog site. ().
Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
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}`;
1
2
rulesets:- javascript-best-practices # Rules to enforce JavaScript best practices.