no-contradictory-type-predicate
Keep explicit type predicates consistent with their primitive, array or record membership check.
closedLiteralPredicatecontradictoryPredicatenullAccepteduncheckedArrayElementsuncheckedRecordFields Rule source Tests Catalog JSON Why
TypeScript trusts an explicit type predicate without verifying its implementation. A contradictory check can admit the wrong primitive, overclaim a closed literal or empty domain, accept null as a non-null object, or remove valid alternatives from the false branch.
Fix
Match the predicate to every value the check accepts and rejects. Check literal membership for a closed domain and exclude null when promising a non-null object. Use a boolean return for an intentional value filter; preserve required public and callback contracts.
Examples
function texts(value: unknown): value is string[] { return Array.isArray(value);}function texts(value: unknown): value is string[] { return ( Array.isArray(value) && value.every((item: unknown) => typeof item === "string") );}function ready(value: unknown): value is "ready" { return typeof value === "string";}function ready(value: "ready" | null): value is "ready" { return typeof value === "string";}function nonPrimitive(value: unknown): value is object { return typeof value === "object";}function nonPrimitive(value: unknown): value is object { return (typeof value === "object" && value !== null) || typeof value === "function";}function isText(value: unknown): value is string { return typeof value === "number";}function isText(value: unknown): value is string { return typeof value === "string";}function impossible(value: unknown): value is never { return typeof value === "number";}function impossible(value: unknown): value is never { return false;}type Account = { id: string };function account(value: unknown): value is Account { return typeof value === "object" && value !== null;}type Account = { id: string };function account(value: unknown): value is Account { return ( typeof value === "object" && value !== null && "id" in value && typeof value.id === "string" );}