Skip to content

Commit

Permalink
add ManagedRuntime type utils (Context and Error) (#3005)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim <[email protected]>
  • Loading branch information
gcanti and tim-smart committed Jun 20, 2024
1 parent 91bf8a2 commit 8c3b8a2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-parrots-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

add `ManagedRuntime` type utils (`Context`, and `Error`)
20 changes: 20 additions & 0 deletions packages/effect/dtslint/ManagedRuntime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { hole } from "effect/Function"
import type * as Layer from "effect/Layer"
import * as ManagedRuntime from "effect/ManagedRuntime"

declare const layer: Layer.Layer<"context", "error">
const runtime = ManagedRuntime.make(layer)

// -------------------------------------------------------------------------------------
// Context
// -------------------------------------------------------------------------------------

// $ExpectType "context"
hole<ManagedRuntime.ManagedRuntime.Context<typeof runtime>>()

// -------------------------------------------------------------------------------------
// Error
// -------------------------------------------------------------------------------------

// $ExpectType "error"
hole<ManagedRuntime.ManagedRuntime.Error<typeof runtime>>()
16 changes: 16 additions & 0 deletions packages/effect/src/ManagedRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ import type * as Layer from "./Layer.js"
import type { Pipeable } from "./Pipeable.js"
import type * as Runtime from "./Runtime.js"

/**
* @since 3.4.0
*/
export declare namespace ManagedRuntime {
/**
* @category type-level
* @since 3.4.0
*/
export type Context<T extends ManagedRuntime<any, any>> = [T] extends [ManagedRuntime<infer R, infer _E>] ? R : never
/**
* @category type-level
* @since 3.4.0
*/
export type Error<T extends ManagedRuntime<any, any>> = [T] extends [ManagedRuntime<infer _R, infer E>] ? E : never
}

/**
* @since 2.0.0
* @category models
Expand Down

0 comments on commit 8c3b8a2

Please sign in to comment.