NonEmptyArray<A> is not assignable to [A, ...A[]]
Author: geoffreytoolsCreated Feb 4, 2023Updated Apr 22, 2024
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[]]'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 |
Source: gcanti/fp-ts