millsp / ts-toolbelt

πŸ‘· TypeScript's largest type utility library

Home Page:https://millsp.github.io/ts-toolbelt/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

List.Drop<L, N, '<-'> drops all *but* N items

supposedly opened this issue Β· comments

🐞 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