Repository navigation
v0.64.0
Minor Changes
-
#567
dcb3fe5Thanks @mattiamanzati! - Added new diagnosticcatchAllToMapErrorthat suggests usingEffect.mapErrorinstead ofEffect.catchAll+Effect.failwhen the callback only wraps the error.Before:
Effect.catchAll((cause) => Effect.fail(new MyError(cause)));
After:
Effect.mapError((cause) => new MyError(cause));
The diagnostic includes a quick fix that automatically transforms the code.
-
#555
0424000Thanks @mattiamanzati! - AddglobalErrorInEffectCatchdiagnostic to detect global Error types in catch callbacksThis new diagnostic warns when catch callbacks in
Effect.tryPromise,Effect.try,Effect.tryMap, orEffect.tryMapPromisereturn the globalErrortype instead of typed errors.Using the global
Errortype in Effect failures is not recommended as they can get merged together, making it harder to distinguish between different error cases. Instead, it's better to use tagged errors (likeData.TaggedError) or custom errors with discriminator properties to enable proper type checking and error handling.Example of code that triggers the diagnostic:
Effect.tryPromise({ try: () => fetch("http://example.com"), catch: () => new Error("Request failed"), // ⚠️ Warning: returns global Error type });
Recommended approach:
class FetchError extends Data.TaggedError("FetchError")<{ cause: unknown; }> {} Effect.tryPromise({ try: () => fetch("http://example.com"), catch: (e) => new FetchError({ cause: e }), // ✅ Uses typed error });
This diagnostic also improves the clarity message for the
leakingRequirementsdiagnostic by adding additional guidance on how services should be collected in the layer creation body. -
#558
cc5feb1Thanks @mattiamanzati! - AddlayerMergeAllWithDependenciesdiagnostic to detect interdependencies inLayer.mergeAllcallsThis new diagnostic warns when
Layer.mergeAllis called with layers that have interdependencies, where one layer provides a service that another layer in the same call requires.Layer.mergeAllcreates layers in parallel, so dependencies between layers will not be satisfied. This can lead to runtime errors when trying to use the merged layer.Example of code that triggers the diagnostic:
export class DbConnection extends Effect.Service<DbConnection>()( "DbConnection", { succeed: {}, } ) {} export class FileSystem extends Effect.Service<FileSystem>()("FileSystem", { succeed: {}, }) {} export class Cache extends Effect.Service<Cache>()("Cache", { effect: Effect.as(FileSystem, {}), // Cache requires FileSystem }) {} // ⚠️ Warning on FileSystem.Default const layers = Layer.mergeAll( DbConnection.Default, FileSystem.Default, // This provides FileSystem Cache.Default // This requires FileSystem );
Recommended approach:
// Provide FileSystem separately before merging const layers = Layer.mergeAll(DbConnection.Default, Cache.Default).pipe( Layer.provideMerge(FileSystem.Default) );
The diagnostic correctly handles pass-through layers (layers that both provide and require the same type) and only reports on layers that actually provide dependencies needed by other layers in the same
mergeAllcall. -
#557
83ce411Thanks @mattiamanzati! - AddmissingLayerContextdiagnostic to detect missing service requirements in Layer definitionsThis new diagnostic provides better error readability when you're missing service requirements in your Layer type definitions. It works similarly to the existing
missingEffectContextdiagnostic but specifically checks theRIn(requirements input) parameter of Layer types.Example of code that triggers the diagnostic:
import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; class ServiceA extends Effect.Service<ServiceA>()("ServiceA", { succeed: { a: 1 }, }) {} class ServiceB extends Effect.Service<ServiceB>()("ServiceB", { succeed: { a: 2 }, }) {} declare const layerWithServices: Layer.Layer<ServiceA, never, ServiceB>; function testFn(layer: Layer.Layer<ServiceA>) { return layer; } // ⚠️ Error: Missing 'ServiceB' in the expected Layer context. testFn(layerWithServices);
The diagnostic helps catch type mismatches early by clearly indicating which service requirements are missing when passing layers between functions or composing layers together.
-
#562
57d5af2Thanks @mattiamanzati! - AddoverviewCLI command that provides an overview of Effect-related exports in a project.The command analyzes TypeScript files and reports all exported yieldable errors, services (Context.Tag, Effect.Tag, Effect.Service), and layers with their types, file locations, and JSDoc descriptions. A progress spinner shows real-time file processing status.
Usage:
effect-language-service overview --file path/to/file.ts effect-language-service overview --project tsconfig.json
Example output:
✔ Processed 3 file(s) Overview for 3 file(s). Yieldable Errors (1) NotFoundError ./src/errors.ts:5:1 NotFoundError Services (2) DbConnection ./src/services/db.ts:6:1 Manages database connections Layers (1) AppLive ./src/layers/app.ts:39:14 Layer<Cache | UserRepository, never, never>
Patch Changes
-
#561
c3b3bd3Thanks @mattiamanzati! - Add descriptions to CLI commands usingCommand.withDescriptionfor improved help output when using--helpflag. -
#565
2274aefThanks @mattiamanzati! - FixunnecessaryPipediagnostic and refactor not working with namespace imports fromeffect/Function(e.g.,Function.pipe()orFn.pipe()) -
#560
75a480eThanks @mattiamanzati! - Improve diagnostic message forunsupportedServiceAccessorswhen used withEffect.TagWhen the
unsupportedServiceAccessorsdiagnostic is triggered on anEffect.Tagclass (which doesn't allow disabling accessors), the message now includes a helpful suggestion to useContext.Taginstead:export class MyService extends Effect.Tag("MyService")< MyService, { method: <A>(value: A) => Effect.Effect<A>; } >() {} // Diagnostic: Even if accessors are enabled, accessors for 'method' won't be available // because the signature have generic type parameters or multiple call signatures. // Effect.Tag does not allow to disable accessors, so you may want to use Context.Tag instead.
-
#559
4c1f809Thanks @mattiamanzati! - Improve Layer Magic refactor ordering by considering both provided and required service countsThe Layer Magic refactor now uses a combined ordering heuristic that considers both:
- The number of services a layer provides
- The number of services a layer requires
This results in more optimal layer composition order, especially in complex dependency graphs where layers have varying numbers of dependencies.
-
#566
036c491Thanks @mattiamanzati! - Simplify diagnostic messages for global Error type usageThe diagnostic messages for
globalErrorInEffectCatchandglobalErrorInEffectFailurenow use the more generic term "tagged errors" instead of "tagged errors (Data.TaggedError)" to provide cleaner, more concise guidance.