src/content/docs/linter/rules/use-valid-typeof.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/correctness/useValidTypeof`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`valid-typeof`](https://eslint.org/docs/latest/rules/valid-typeof){
"linter": {
"rules": {
"correctness": {
"useValidTypeof": "error"
}
}
}
}
This rule checks that the result of a typeof expression is compared to a valid value.
typeof foo === "strnig";
typeof foo == "undefimed";
typeof bar != "nunber";
typeof foo === undefined;
typeof foo == 0;
typeof foo === "string";
typeof bar == "undefined";
typeof bar === typeof qux;
typeof foo === bar