File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -909,6 +909,16 @@ type HeadNode<T> = {
909909 prev : ListNode < T > | HeadNode < T > ;
910910} ;
911911
912+ /**
913+ * When a list is empty the head is a reference with pointers to itself
914+ * So this type represents that self referential state
915+ */
916+ type EmptyNode = {
917+ value : null ;
918+ next : EmptyNode ;
919+ prev : EmptyNode ;
920+ } ;
921+
912922/**
913923 * A sequential list of items in a circularly linked list
914924 * @remarks
@@ -919,7 +929,7 @@ type HeadNode<T> = {
919929 * @internal
920930 */
921931export class List < T = unknown > {
922- private readonly head : HeadNode < T > ;
932+ private readonly head : HeadNode < T > | EmptyNode ;
923933 private count : number ;
924934
925935 get length ( ) {
@@ -937,10 +947,10 @@ export class List<T = unknown> {
937947 // declaring a complete and consistently key ordered
938948 // object is beneficial to the runtime optimizations
939949 this . head = {
940- next : null as unknown as HeadNode < T > ,
941- prev : null as unknown as HeadNode < T > ,
950+ next : null ,
951+ prev : null ,
942952 value : null
943- } ;
953+ } as unknown as EmptyNode ;
944954 this . head . next = this . head ;
945955 this . head . prev = this . head ;
946956 }
You can’t perform that action at this time.
0 commit comments