{"record":{"id":"b839e0176fdeebea","repo":"oxc-project/oxc","slug":"invalid-typeof-comparison-value","errorCode":null,"errorMessage":"Invalid `typeof` comparison value.","messagePattern":"Invalid `typeof` comparison value\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/valid_typeof.rs","lineNumber":26,"sourceCode":"use serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn not_string(help: Option<&'static str>, span: Span) -> OxcDiagnostic {\n    let mut d =\n        OxcDiagnostic::warn(\"`typeof` comparisons should be to string literals.\").with_label(span);\n    if let Some(x) = help {\n        d = d.with_help(x);\n    }\n    d\n}\n\nfn invalid_value(help: Option<String>, span: Span) -> OxcDiagnostic {\n    let mut d = OxcDiagnostic::warn(\"Invalid `typeof` comparison value.\").with_label(span);\n    if let Some(x) = help {\n        d = d.with_help(x);\n    }\n    d\n}\n\n#[derive(Debug, Clone, Default, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct ValidTypeof {\n    /// The `requireStringLiterals` option when set to `true`, allows the comparison of `typeof`\n    /// expressions with only string literals or other `typeof` expressions, and disallows\n    /// comparisons to any other value. Default is `false`.\n    ///\n    /// With `requireStringLiterals` set to `true`, the following are examples of **incorrect** code:\n    /// ```js\n    /// typeof foo === undefined\n    /// typeof bar == Object\n    /// typeof baz === \"strnig\"","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/valid_typeof.rs#L8-L44","documentation":"The `invalid_value` branch of oxlint's `valid-typeof`: the typeof expression is compared to a string literal, but the literal is not one of the eight values typeof can return (\"undefined\", \"object\", \"boolean\", \"number\", \"string\", \"function\", \"symbol\", \"bigint\") — typically a typo.","triggerScenarios":"`typeof foo === \"str\"`, `typeof x !== \"interger\"`, `typeof f === \"fuction\"` — any misspelled or impossible typeof result literal on either side of the comparison.","commonSituations":"Typos in type-guard helper functions; wrong casing (\"Number\" vs \"number\"); made-up names like \"array\" written from memory; older code never checked by a compiler.","solutions":["Correct the literal to one of the eight valid typeof results","Use `Array.isArray(x)` for array checks instead of typeof","Cross-check with `tsc --noEmit`: TypeScript rejects typeof comparisons with impossible literals"],"exampleFix":"// before — \"str\" is not a possible typeof result\nconst isStr = typeof value === \"str\";\n\n// after\nconst isStr = typeof value === \"string\";","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"valid-typeof\": \"error\" } }\n// dual gate: npx tsc --noEmit && npx oxlint --deny-warnings src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Memorize the eight typeof results: undefined, object, boolean, number, string, function, symbol, bigint","Use Array.isArray for arrays — typeof never returns \"array\"","Let tsc cross-check typeof literals in CI","Keep type-guard helpers small and unit-tested so typos surface immediately"],"tags":["lint","oxlint","eslint","typeof","correctness","typo"],"backgroundTag":"invalid-typeof-comparison","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}