-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
add index argument to many functions in ReadonlyArray #1850
Conversation
🦋 Changeset detectedLatest commit: cb09879 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matheuspuel I would add some dtslint tests, based on my experiments these tests fail:
// file: /packages/effect/dtslint/ReadonlyArray.ts
// -------------------------------------------------------------------------------------
// takeWhile
// -------------------------------------------------------------------------------------
ReadonlyArray.takeWhile(numbersOrStrings, (
_item // $ExpectType string | number
) => true)
// fails: Parameter '_item' implicitly has an 'any' type.ts(7006)
ReadonlyArray.takeWhile(numbersOrStrings, (
_item, // $ExpectType string | number
_i // $ExpectType number
) => true)
pipe(
numbersOrStrings,
ReadonlyArray.takeWhile((
_item // $ExpectType string | number
) => true)
)
// fails: Parameter '_item' implicitly has an 'any' type.ts(7006)
pipe(
numbersOrStrings,
ReadonlyArray.takeWhile((
_item, // $ExpectType string | number
_i // $ExpectType number
) => true)
)
unless you add a i: number
parameter to refinements too:
export const takeWhile: {
<A, B extends A>(refinement: (a: A, i: number) => a is B): (self: Iterable<A>) => Array<B>
<B extends A, A = B>(predicate: (a: A, i: number) => boolean): (self: Iterable<B>) => Array<B>
<A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>
} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {
let i = 0
const out: Array<A> = []
for (const a of self) {
if (!predicate(a, i)) {
break
}
out.push(a)
i++
}
return out
})
No description provided.