r/badcode • • Jun 19 '21

typescript Check if binary tree is balanced...

Post image
221 Upvotes

44 comments sorted by

View all comments

-1

u/ef02 Jun 20 '21

The | null is unnecessary in TypeScript, but other than that, it seems fine.

3

u/MrPancholi Jun 20 '21

Why is null unnecessary? Wouldn't that cause a conflict with the type?

0

u/ef02 Jun 20 '21

Oh man...I wish I could answer any "why" question about JS/TS...but all I know is that the TS transpiler doesn't complain when I do something like that without the | null 😂

I believe that setting an object type to null is fine, but undefined / unknown would cause an error.