{"record":{"id":"909ed3d942d61d2d","repo":"doocs/leetcode","slug":"equal-909ed3","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.md","lineNumber":80,"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":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/doocs/leetcode/blob/f84f361dc403a65c4c031f6e0774297cc377f00a/solution/2700-2799/2704.To Be Or Not To Be/README.md#L62-L98","documentation":"README TypeScript tab for LeetCode 2704: notToBe throws Error('Equal') when val === notToBeVal. It is the complement assertion — it only succeeds when the two any-typed values are strictly different, and it fires when they turn out to be the same.","triggerScenarios":"expect(1).notToBe(1), expect(undefined).notToBe(undefined), expect(sameRef).notToBe(sameRef).","commonSituations":"Copying README examples and flipping the wrong assertion; believing two equal-looking values are distinct (e.g. interned strings in JS); testing the utility with toThrow and passing the wrong message string ('Not Equal' vs 'Equal').","solutions":["Verify the pair actually differs; if equal, use toBe","Create separate objects when you need reference inequality","When asserting the throw, match the exact message 'Equal'","Remember only toBe throws 'Not Equal' — notToBe throws 'Equal'"],"exampleFix":"// before\nexpect(1).notToBe(1); // throws 'Equal'\n\n// after\nexpect(1).notToBe('1'); // true (strict inequality)","handlingStrategy":"validation","validationCode":"if (val !== notToBeVal) { expect(val).notToBe(notToBeVal); }","typeGuard":"const strictNotEqual = (a: unknown, b: unknown): boolean => a !== b;","tryCatchPattern":"try { expect(v).notToBe(e); } catch (e) { if ((e as Error).message !== 'Equal') throw e; }","preventionTips":["Assert the exact 'Equal' message in 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"}