{"record":{"id":"45298d5c03f35ff8","repo":"doocs/leetcode","slug":"equal-45298d","errorCode":null,"errorMessage":"Equal","messagePattern":"Equal","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"solution/2700-2799/2704.To Be Or Not To Be/README_EN.md","lineNumber":79,"sourceCode":"#### TypeScript\n\n```ts\ntype ToBeOrNotToBe = {\n    toBe: (val: any) => boolean;\n    notToBe: (val: any) => boolean;\n};\n\nfunction expect(val: any): ToBeOrNotToBe {\n    return {\n        toBe: (toBeVal: any) => {\n            if (val !== toBeVal) {\n                throw new Error('Not Equal');\n            }\n            return true;\n        },\n        notToBe: (notToBeVal: any) => {\n            if (val === notToBeVal) {\n                throw new Error('Equal');\n            }\n            return true;\n        },\n    };\n}\n\n/**\n * expect(5).toBe(5); // true\n * expect(5).notToBe(5); // throws \"Equal\"\n */\n```\n\n#### JavaScript\n\n```js\n/**\n * @param {string} val\n * @return {Object}","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/doocs/leetcode/blob/f84f361dc403a65c4c031f6e0774297cc377f00a/solution/2700-2799/2704.To Be Or Not To Be/README_EN.md#L61-L97","documentation":"English README TypeScript tab, notToBe branch of LeetCode 2704: throws Error('Equal') when val === notToBeVal. The inverted assertion only returns true for strictly different values; identical primitives or the same object reference trip the guard.","triggerScenarios":"expect(true).notToBe(true), expect('a').notToBe('a'), expect(x).notToBe(x) with the same variable on both sides.","commonSituations":"Adapting the sample tests; asserting the wrong message text; assuming two separately written literals would be distinguishable references (primitives are compared by value).","solutions":["Verify inequality is actually expected; otherwise switch to toBe","For object inequality, pass distinct instances ({}).notToBe({}) works","Use the exact 'Equal' message in toThrow checks","Re-read the API: notToBe is the negation of toBe"],"exampleFix":"// before\nexpect('a').notToBe('a'); // throws 'Equal'\n\n// after\nexpect('a').notToBe('b'); // true","handlingStrategy":"validation","validationCode":"if (val !== notToBeVal) { expect(val).notToBe(notToBeVal); }","typeGuard":"function differs(a: unknown, b: unknown): boolean { return a !== b; }","tryCatchPattern":"try { expect(v).notToBe(e); } catch (e) { if ((e as Error).message !== 'Equal') throw e; }","preventionTips":["Pass distinct references for object inequality tests"],"tags":["typescript","assertion","equality","documentation"],"backgroundTag":"assertion-equality-failure","analyzedSha":"f84f361dc403a65c4c031f6e0774297cc377f00a","analyzedAt":"2026-08-27T04:29:31.522Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}