Skip to content

Commit

Permalink
ensure isTupleOf works with ReadonlyArray (#2883)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jun 6, 2024
1 parent 67f160a commit 64565db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions packages/effect/dtslint/Predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { pipe } from "effect/Function"
import * as Predicate from "effect/Predicate"

declare const u: unknown
declare const anys: Array<any>
declare const unknowns: Array<unknown>
declare const numberOrNull: Array<number | null>
declare const numberOrUndefined: Array<number | undefined>
declare const numberOrNullOrUndefined: Array<number | null | undefined>
declare const anys: ReadonlyArray<any>
declare const unknowns: ReadonlyArray<unknown>
declare const numberOrNull: ReadonlyArray<number | null>
declare const numberOrUndefined: ReadonlyArray<number | undefined>
declare const numberOrNullOrUndefined: ReadonlyArray<number | null | undefined>

// -------------------------------------------------------------------------------------
// isString
Expand Down Expand Up @@ -180,7 +180,7 @@ unknowns.filter(Predicate.isReadonlyRecord)
// isTupleOf
// -------------------------------------------------------------------------------------

if (Predicate.isTupleOf(3)(unknowns)) {
if (Predicate.isTupleOf(unknowns, 3)) {
// $ExpectType [unknown, unknown, unknown]
unknowns
}
Expand All @@ -189,7 +189,7 @@ if (Predicate.isTupleOf(3)(unknowns)) {
// isTupleOfAtLeast
// -------------------------------------------------------------------------------------

if (Predicate.isTupleOfAtLeast(3)(unknowns)) {
if (Predicate.isTupleOfAtLeast(unknowns, 3)) {
// $ExpectType [unknown, unknown, unknown, ...unknown[]]
unknowns
}
Expand Down
12 changes: 6 additions & 6 deletions packages/effect/src/Predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export const mapInput: {
* @since 3.3.0
*/
export const isTupleOf: {
<N extends number>(n: N): <T>(self: Array<T>) => self is TupleOf<N, T>
<T, N extends number>(self: Array<T>, n: N): self is TupleOf<N, T>
} = dual(2, <T, N extends number>(self: Array<T>, n: N): self is TupleOf<N, T> => self.length === n)
<N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>
<T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>
} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T> => self.length === n)

/**
* Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.
Expand All @@ -107,9 +107,9 @@ export const isTupleOf: {
* @since 3.3.0
*/
export const isTupleOfAtLeast: {
<N extends number>(n: N): <T>(self: Array<T>) => self is TupleOfAtLeast<N, T>
<T, N extends number>(self: Array<T>, n: N): self is TupleOfAtLeast<N, T>
} = dual(2, <T, N extends number>(self: Array<T>, n: N): self is TupleOfAtLeast<N, T> => self.length >= n)
<N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>
<T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>
} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T> => self.length >= n)

/**
* Tests if a value is `truthy`.
Expand Down

0 comments on commit 64565db

Please sign in to comment.