Created
January 27, 2021 02:13
-
-
Save stern-shawn/2d517df61858f890b55d31bf85441c6d to your computer and use it in GitHub Desktop.
Enable typesafe arr.shift() inside of an if check for if(arr.length) { arr.shift() }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const isShiftable = <T>(arr: T[]): arr is { shift(): T } & Array<T> => arr.length > 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helps to counter this sheer annoyance:
to this