List.Drop<L, N, '<-'> drops all *but* N items
supposedly opened this issue Β· comments
hadi tarhini commented
π Bug Report
Describe the bug
List.Drop<L, N>
's documentation says it removes N
entries out of L
. However, when way
is set to '<-'
, it retains only the first N entries and drops everything else.
Reproduce the bug
import {L} from "ts-toolbelt";
type Foo = [0, 1, 2, 3, 4, 5];
type DropFirst2 = L.Drop<Foo, 2>; // DropFirst2: [2, 3, 4, 5]
type DropLast2 = L.Drop<Foo, 2, '<-'>; // DropLast2: [0, 1]
// example workaround:
type ReallyDropLast2 = L.Reverse<L.Drop<L.Reverse<Foo>, 2>>; // ReallyDropLast2: [0, 1, 2, 3]
// or with pure TS:
type AlsoDropLast2 = Foo extends [...infer Start, unknown, unknown] ? Start : Foo;
Expected behavior
Expected DropLast2
to have the type [0, 1, 2, 3]
.
In other words, List.Drop<L, N, '<-'>
should only drop the last N entries and retain the rest, mirroring what it does with the default way = '->'
.
Possible Solution
Not sure if this is intentional and just a misunderstanding from me :) If so, the docs should make it explicit!
Additional context
Version 9.6.0