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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NonEmptyArray<A> is not assignable to [A, ...A[]] #1830

Open
geoffreytools opened this issue Feb 4, 2023 · 1 comment
Open

NonEmptyArray<A> is not assignable to [A, ...A[]] #1830

geoffreytools opened this issue Feb 4, 2023 · 1 comment
Milestone

Comments

@geoffreytools
Copy link

🐛 Bug report

Current Behavior

NonEmptyArray<A> is not assignable to [A, ...A[]].

Expected behavior

One should be able to use NonEmptyArray (and ReadonlyNonEmptyArray) with functions using the open-ended tuple syntax for their type constraints.

Reproducible example

import { NonEmptyArray, of } from 'fp-ts/lib/NonEmptyArray';

const foo = (arr: [unknown, ...unknown[]]) => arr;

foo(of(0));
//  ~~~~~
// Argument of type 'NonEmptyArray<number>' is not assignable
// to parameter of type '[unknown, ...unknown[]]'

playground

Suggested solution(s)

- export interface NonEmptyArray<A> extends Array<A> {
-    0: A
- }
+ export type NonEmptyArray<A> = [A, ...A[]];

Your environment

Which versions of fp-ts are affected by this issue? Did this work in previous versions of fp-ts?

Software Version(s)
fp-ts I don't know. NonEmptyArray2v was introduced in 1.15.0
TypeScript at least since 3.3.3
@orangebokov
Copy link

it wouldn't be bad to see this in fp-ts

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

3 participants