Skip to content

Commit

Permalink
fix types for bindAll
Browse files Browse the repository at this point in the history
  • Loading branch information
maksim.khramtsov committed Aug 28, 2024
1 parent 11a76cd commit 2cdf5df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
33 changes: 29 additions & 4 deletions packages/effect/src/internal/effect/circular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { currentScheduler } from "../../Scheduler.js"
import type * as Scope from "../../Scope.js"
import type * as Supervisor from "../../Supervisor.js"
import type * as Synchronized from "../../SynchronizedRef.js"
import type * as Types from "../../Types.js"
import * as internalCause from "../cause.js"
import * as effect from "../core-effect.js"
import * as core from "../core.js"
Expand Down Expand Up @@ -707,7 +708,16 @@ export const zipWithFiber = dual<

/* @internal */
export const bindAll: {
<A extends object, X extends Record<string, Effect.Effect<any, any, any>>, O extends Effect.All.Options>(
<
A extends object,
X extends Record<string, Effect.Effect<any, any, any>>,
O extends {
readonly concurrency?: Types.Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly mode?: "default" | "validate" | "either" | undefined
readonly concurrentFinalizers?: boolean | undefined
}
>(
f: (a: A) => [Extract<keyof X, keyof A>] extends [never] ? X : `Duplicate keys`,
options?: undefined | O
): <E1, R1>(self: Effect.Effect<A, E1, R1>) => Effect.Effect<
Expand All @@ -729,13 +739,23 @@ export const bindAll: {
<
A extends object,
X extends Record<string, Effect.Effect<any, any, any>>,
O extends Effect.All.Options,
O extends {
readonly concurrency?: Types.Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly mode?: "default" | "validate" | "either" | undefined
readonly concurrentFinalizers?: boolean | undefined
},
E1,
R1
>(
self: Effect.Effect<A, E1, R1>,
f: (a: A) => [Extract<keyof X, keyof A>] extends [never] ? X : `Duplicate keys`,
options?: undefined | Effect.All.Options
options?: undefined | {
readonly concurrency?: Types.Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly mode?: "default" | "validate" | "either" | undefined
readonly concurrentFinalizers?: boolean | undefined
}
): Effect.Effect<
{
[K in keyof X | keyof A]: K extends keyof A ? A[K] :
Expand All @@ -755,7 +775,12 @@ export const bindAll: {
} = dual((args) => core.isEffect(args[0]), <
A extends object,
X extends Record<string, Effect.Effect<any, any, any>>,
O extends Effect.All.Options,
O extends {
readonly concurrency?: Types.Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly mode?: "default" | "validate" | "either" | undefined
readonly concurrentFinalizers?: boolean | undefined
},
E1,
R1
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/test/Effect/do-notation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("do notation", () => {

describe("bindAll", () => {
it("succeed", () => {
const getTest = <O extends Effect.All.Options>(options: O) =>
const getTest = <O extends { mode: "default" | "either" | "validate" }>(options: O) =>
Effect.Do.pipe(
Effect.bind("x", () => Effect.succeed(2)),
Effect.bindAll(({ x }) => ({
Expand Down Expand Up @@ -77,7 +77,7 @@ describe("do notation", () => {
})

it("with failure", () => {
const getTest = <O extends Effect.All.Options>(options: O) =>
const getTest = <O extends { mode: "default" | "either" | "validate" }>(options: O) =>
Effect.Do.pipe(
Effect.bind("x", () => Effect.succeed(2)),
Effect.bindAll(({ x }) => ({
Expand Down

0 comments on commit 2cdf5df

Please sign in to comment.