Skip to content

Commit

Permalink
fix Unify for RcRef & Deferred (#3678)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Oct 6, 2024
1 parent 95ccc0e commit 8181cdc
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-experts-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

fix Unify for RcRef & Deferred
32 changes: 16 additions & 16 deletions packages/effect/dtslint/Unify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export type SubscriptionRefUnify = Unify.Unify<
| SubscriptionRef.SubscriptionRef<1>
| SubscriptionRef.SubscriptionRef<"a">
>
// $ExpectType RcRef<"a" | 1, "b" | 2>
// $ExpectType RcRef<1, 2> | RcRef<"a", "b">
export type RcRefUnify = Unify.Unify<
| RcRef.RcRef<1, 2>
| RcRef.RcRef<"a", "b">
Expand Down Expand Up @@ -130,40 +130,40 @@ export type ResourceUnify = Unify.Unify<
| Resource.Resource<any, any>
>

// $ExpectType 0 | Option<string | number> | Ref<1> | SynchronizedRef<1> | SubscriptionRef<1> | Deferred<1, 2> | Deferred<"a", "b"> | Fiber<"a" | 1, "b" | 2> | RuntimeFiber<"a" | 1, "b" | 2> | ManagedRuntime<1, 2> | ManagedRuntime<"a", "b"> | Queue<1> | Queue<"a"> | Dequeue<"a" | 1> | ScopedRef<1> | ScopedRef<"a"> | Resource<1, 2> | Ref<"A"> | SynchronizedRef<"A"> | SubscriptionRef<"A"> | FiberRef<12> | FiberRef<"a2"> | Resource<"a", never> | Latch | Either<1 | "A", 0 | "E"> | Effect<1 | "A", 0 | "E", "R" | "R1"> | RcRef<1 | "A", 0 | "E">
// $ExpectType 0 | Option<string | number> | Ref<1> | Ref<"a"> | SynchronizedRef<1> | SynchronizedRef<"a"> | SubscriptionRef<1> | SubscriptionRef<"a"> | RcRef<"a", "b"> | Deferred<"a", "b"> | FiberRef<1> | FiberRef<"a"> | ManagedRuntime<"a", "b"> | Queue<1> | Queue<"a"> | Dequeue<"a" | 1> | ScopedRef<1> | ScopedRef<"a"> | Resource<"a", "b"> | RcRef<1, 0> | Deferred<1, 0> | Resource<1, 0> | Latch | ManagedRuntime<1, 0> | Fiber<"a" | 1, 0 | "b"> | RuntimeFiber<"a" | 1, 0 | "b"> | Either<"a" | 1, 0 | "b"> | Effect<"a" | 1, 0 | "b", "R" | "R1">
export type AllUnify = Unify.Unify<
| Either.Either<1, 0>
| Either.Either<"A", "E">
| Either.Either<"a", "b">
| Option.Option<number>
| Option.Option<string>
| Effect.Effect<"A", "E", "R">
| Effect.Effect<"a", "b", "R">
| Effect.Effect<1, 0, "R1">
| Ref.Ref<1>
| Ref.Ref<"A">
| Ref.Ref<"a">
| SynchronizedRef.SynchronizedRef<1>
| SynchronizedRef.SynchronizedRef<"A">
| SynchronizedRef.SynchronizedRef<"a">
| SubscriptionRef.SubscriptionRef<1>
| SubscriptionRef.SubscriptionRef<"A">
| SubscriptionRef.SubscriptionRef<"a">
| RcRef.RcRef<1, 0>
| RcRef.RcRef<"A", "E">
| Deferred.Deferred<1, 2>
| RcRef.RcRef<"a", "b">
| Deferred.Deferred<1, 0>
| Deferred.Deferred<"a", "b">
| FiberRef.FiberRef<12>
| FiberRef.FiberRef<"a2">
| Fiber.Fiber<1, 2>
| FiberRef.FiberRef<1>
| FiberRef.FiberRef<"a">
| Fiber.Fiber<1, 0>
| Fiber.Fiber<"a", "b">
| Fiber.RuntimeFiber<1, 2>
| Fiber.RuntimeFiber<1, 0>
| Fiber.RuntimeFiber<"a", "b">
| Queue.Queue<1>
| Queue.Queue<"a">
| Queue.Dequeue<1>
| Queue.Dequeue<"a">
| ScopedRef.ScopedRef<1>
| ScopedRef.ScopedRef<"a">
| Resource.Resource<1, 2>
| Resource.Resource<"a">
| Resource.Resource<1, 0>
| Resource.Resource<"a", "b">
| Effect.Latch
| ManagedRuntime.ManagedRuntime<1, 2>
| ManagedRuntime.ManagedRuntime<1, 0>
| ManagedRuntime.ManagedRuntime<"a", "b">
| 0
>
2 changes: 1 addition & 1 deletion packages/effect/src/Deferred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface Deferred<in out A, in out E = never> extends Effect.Effect<A, E
* @since 3.8.0
*/
export interface DeferredUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
Deferred?: () => Extract<A[Unify.typeSymbol], Deferred<any>>
Deferred?: () => Extract<A[Unify.typeSymbol], Deferred<any, any>>
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type BackingQueueTypeId = typeof BackingQueueTypeId
* @since 2.0.0
* @category models
*/
export interface Queue<in out A> extends Enqueue<A>, Dequeue<A>, Pipeable {
export interface Queue<in out A> extends Enqueue<A>, Dequeue<A> {
/** @internal */
readonly queue: BackingQueue<A>
/** @internal */
Expand Down Expand Up @@ -134,7 +134,7 @@ export interface Enqueue<in A> extends Queue.EnqueueVariance<A>, BaseQueue, Pipe
* @since 2.0.0
* @category models
*/
export interface Dequeue<out A> extends Effect.Effect<A>, Queue.DequeueVariance<A>, BaseQueue, Pipeable {
export interface Dequeue<out A> extends Effect.Effect<A>, Queue.DequeueVariance<A>, BaseQueue {
/**
* Takes the oldest value in the queue. If the queue is empty, this will return
* a computation that resumes when an item has been added to the queue.
Expand Down
3 changes: 1 addition & 2 deletions packages/effect/src/RcRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ export interface RcRef<out A, out E = never>
* @since 3.8.0
*/
export interface RcRefUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
RcRef?: () => A[Unify.typeSymbol] extends RcRef<infer A0, infer E0> | infer _ ? RcRef<A0, E0>
: never
RcRef?: () => Extract<A[Unify.typeSymbol], RcRef<any, any>>
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/effect/src/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import type * as Effect from "./Effect.js"
import type * as Exit from "./Exit.js"
import * as internal from "./internal/resource.js"
import type { Pipeable } from "./Pipeable.js"
import type * as Schedule from "./Schedule.js"
import type * as Scope from "./Scope.js"
import type * as ScopedRef from "./ScopedRef.js"
Expand All @@ -30,7 +29,7 @@ export type ResourceTypeId = typeof ResourceTypeId
* @since 2.0.0
* @category models
*/
export interface Resource<in out A, in out E = never> extends Effect.Effect<A, E>, Resource.Variance<A, E>, Pipeable {
export interface Resource<in out A, in out E = never> extends Effect.Effect<A, E>, Resource.Variance<A, E> {
/** @internal */
readonly scopedRef: ScopedRef.ScopedRef<Exit.Exit<A, E>>
/** @internal */
Expand Down
23 changes: 9 additions & 14 deletions packages/effect/src/Unify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,21 @@ export declare const ignoreSymbol: unique symbol
*/
export type ignoreSymbol = typeof ignoreSymbol

type MaybeReturn<F> = F extends () => any ? ReturnType<F> : F
type MaybeReturn<F> = F extends () => infer R ? R : NonNullable<F>

type Values<X extends [any, any]> = X extends any
? { [k in keyof X[0]]-?: k extends X[1] ? never : MaybeReturn<X[0][k]> }[keyof X[0]]
type Values<X extends [any, any]> = X extends [infer A, infer Ignore]
? Exclude<keyof A, Ignore> extends infer k ? k extends keyof A ? MaybeReturn<A[k]> : never : never
: never

type Ignore<X> = X extends {
[ignoreSymbol]?: any
} ? keyof NonNullable<X[ignoreSymbol]>
type Ignore<X> = X extends { [ignoreSymbol]?: infer Obj } ? keyof NonNullable<Obj>
: never

type ExtractTypes<
X extends {
[typeSymbol]?: any
[unifySymbol]?: any
}
> = X extends any ? [
NonNullable<X[unifySymbol]>,
Ignore<X>
]
X
> = X extends {
[typeSymbol]?: infer _Type
[unifySymbol]?: infer _Unify
} ? [NonNullable<_Unify>, Ignore<X>]
: never

type FilterIn<A> = A extends any ? typeSymbol extends keyof A ? A : never : never
Expand Down

0 comments on commit 8181cdc

Please sign in to comment.