Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
supposedly opened this issue Feb 21, 2022 · 0 comments
Open

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

supposedly opened this issue Feb 21, 2022 · 0 comments

Comments

@supposedly
Copy link

supposedly commented Feb 21, 2022

馃悶 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant