Bug Report for https://neetcode.io/problems/invert-a-binary-tree
Problem
On the Invert Binary Tree problem (TypeScript), the starter code includes a commented-out TreeNode class, while the method signature references it:
invertTree(root: TreeNode | null): TreeNode | null
Leaving the class commented out works — the code compiles, runs, and submits without issues, so TreeNode is clearly being injected somewhere above the visible editor region.
The problem is purely in the editor: since the class doesn't exist in the visible context, TreeNode is underlined in red with Cannot find name 'TreeNode' the whole time you're writing your solution. It's confusing and uncomfortable to work with a permanent error on a solution that's actually correct, and it's easy for a user to assume they've broken something.
Uncommenting the class to silence the editor isn't a workaround either — it fails with Duplicate identifier 'TreeNode', colliding with the hidden definition.
Steps to reproduce
- Open Invert Binary Tree and select TypeScript.
- Write a solution with the
TreeNode class left commented out → TreeNode is underlined in the editor, but the code runs and submits fine.
- Uncomment the class to fix the underline →
Duplicate identifier 'TreeNode'.
Expected
TreeNode resolves in the editor's type-checker, so no error is shown for correct code.
Actual
The type-checker doesn't know about TreeNode, so the editor shows an error on every reference to it even though the submission passes.
Suggested fix
Expose TreeNode to the editor's type-checker without redeclaring it at runtime — e.g. an ambient declaration (declare class TreeNode { ... } in a .d.ts loaded into the editor instance) instead of a commented-out class.
Environment
TypeScript · Invert Binary Tree · browser editor
Bug Report for https://neetcode.io/problems/invert-a-binary-tree
Problem
On the Invert Binary Tree problem (TypeScript), the starter code includes a commented-out
TreeNodeclass, while the method signature references it:Leaving the class commented out works — the code compiles, runs, and submits without issues, so
TreeNodeis clearly being injected somewhere above the visible editor region.The problem is purely in the editor: since the class doesn't exist in the visible context,
TreeNodeis underlined in red withCannot find name 'TreeNode'the whole time you're writing your solution. It's confusing and uncomfortable to work with a permanent error on a solution that's actually correct, and it's easy for a user to assume they've broken something.Uncommenting the class to silence the editor isn't a workaround either — it fails with
Duplicate identifier 'TreeNode', colliding with the hidden definition.Steps to reproduce
TreeNodeclass left commented out →TreeNodeis underlined in the editor, but the code runs and submits fine.Duplicate identifier 'TreeNode'.Expected
TreeNoderesolves in the editor's type-checker, so no error is shown for correct code.Actual
The type-checker doesn't know about
TreeNode, so the editor shows an error on every reference to it even though the submission passes.Suggested fix
Expose
TreeNodeto the editor's type-checker without redeclaring it at runtime — e.g. an ambient declaration (declare class TreeNode { ... }in a.d.tsloaded into the editor instance) instead of a commented-out class.Environment
TypeScript · Invert Binary Tree · browser editor