-
-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect typings for Heap#peek #283
Comments
Related: Haven't used that myself yet -- I imagine it's pretty breaky. But here, the unsafe signature is leaking into the API, so maybe something to consider. |
- add explicit return types for Heap.peek()/pop()/pushPop()
- update heap handling (#283)
Thanks @Jannis - I'd say the intention here definitely is @gavinpc-mindgrub thank you for that option, didn't know about that either, but will check it out! |
@postspectacular Awesome, thanks for the quick turnaround! |
@Jannis Hah! Don't get used to it :) Will try to do a new release tomorrow... |
Just pushed a new release! (changelog) 🎉 |
The documentation and TypeScript types for
Heap#peek
say that it always returnsT
. However, the current implementation returnsT | undefined
due to it'sreturn this.values[0]
implementation:Code:
umbrella/packages/heaps/src/heap.ts
Lines 79 to 81 in 8fed74e
Docs: https://docs.thi.ng/umbrella/heaps/classes/_heap_.heap.html#peek
An empty
Heap
orDHeap
would returnundefined
becauseemptyArray[0]
is undefined.My suggestion would be to either make
peek
returnT | undefined
(preferred due to its better developer ergonomics) or make it throw an exception if there are no values (less preferred), and potentially be more explicit in the documentation.The text was updated successfully, but these errors were encountered: