Skip to content

Commit

Permalink
expect errors in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiamanzati committed Feb 23, 2025
1 parent 33e6e94 commit bac42aa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion examples/diagnostics/missingEffectContext_callExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ function testFn(effect: Effect.Effect<number>){
return effect
}

// @ts-expect-error
testFn(effectWithServices)


function testFnWithServiceAB(effect: Effect.Effect<number, never, ServiceA | ServiceB>){
return effect
}

// @ts-expect-error
testFnWithServiceAB(effectWithServices)
4 changes: 4 additions & 0 deletions examples/diagnostics/missingEffectContext_plainAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ declare const effectWithServices: Effect.Effect<number, never, ServiceA | Servic

export const noError: Effect.Effect<number> = Effect.succeed(1)

// @ts-expect-error
export const missingAllServices: Effect.Effect<number> = effectWithServices

// @ts-expect-error
export const missingServiceC: Effect.Effect<number, never, ServiceA | ServiceB> = effectWithServices

export interface EffectSubtyping<A> extends Effect.Effect<A, never, ServiceA | ServiceB> {}

// @ts-expect-error
export const missingServiceCWithSubtyping: EffectSubtyping<number> = effectWithServices

export function missingServiceWithGenericType<A>(service: A){
// @ts-expect-error
const missingServiceA: Effect.Effect<Context.Context<A>> = Effect.context<A>()
return missingServiceA
}
3 changes: 3 additions & 0 deletions examples/diagnostics/missingEffectContext_returnSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ class ServiceC extends Effect.Service<ServiceB>()("ServiceC", {
declare const effectWithServices: Effect.Effect<number, never, ServiceA | ServiceB | ServiceC >

export function testFn(): Effect.Effect<number> {
// @ts-expect-error
return effectWithServices
}

// @ts-expect-error
export const conciseBody: () => Effect.Effect<number> = () => effectWithServices

// @ts-expect-error
export const conciseBodyMissingServiceC: () => Effect.Effect<number, never, ServiceA | ServiceB> = () => effectWithServices
19 changes: 10 additions & 9 deletions test/__snapshots__/diagnostics.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@

exports[`missingEffectContext_callExpression.ts > missingEffectContext_callExpression.ts 1`] = `
"effectWithServices
22:7 - 22:25 | Missing 'ServiceC | ServiceA | ServiceB' in the expected Effect context.
23:7 - 23:25 | Missing 'ServiceC | ServiceA | ServiceB' in the expected Effect context.
effectWithServices
29:20 - 29:38 | Missing 'ServiceC' in the expected Effect context."
30:20 - 30:38 | Missing 'ServiceC' in the expected Effect context."
`;

exports[`missingEffectContext_plainAssignment.ts > missingEffectContext_plainAssignment.ts 1`] = `
" missingAllServices
20:12 - 20:31 | Missing 'ServiceC | ServiceA | ServiceB' in the expected Effect context.
21:12 - 21:31 | Missing 'ServiceC | ServiceA | ServiceB' in the expected Effect context.
missingServiceC
22:12 - 22:28 | Missing 'ServiceC' in the expected Effect context.
24:12 - 24:28 | Missing 'ServiceC' in the expected Effect context.
missingServiceCWithSubtyping
26:12 - 26:41 | Missing 'ServiceC' in the expected Effect context.
29:12 - 29:41 | Missing 'ServiceC' in the expected Effect context.
missingServiceA
29:9 - 29:25 | Missing 'A' in the expected Effect context."
33:9 - 33:25 | Missing 'A' in the expected Effect context."
`;

exports[`missingEffectContext_returnSignature.ts > missingEffectContext_returnSignature.ts 1`] = `
"
// @ts-expect-error
return effectWithServices
18:49 - 19:29 | Missing 'ServiceC | ServiceA | ServiceB' in the expected Effect context.
18:49 - 20:29 | Missing 'ServiceC | ServiceA | ServiceB' in the expected Effect context.
effectWithServices
22:61 - 22:80 | Missing 'ServiceC | ServiceA | ServiceB' in the expected Effect context.
24:61 - 24:80 | Missing 'ServiceC | ServiceA | ServiceB' in the expected Effect context.
effectWithServices
24:104 - 24:123 | Missing 'ServiceC' in the expected Effect context."
27:104 - 27:123 | Missing 'ServiceC' in the expected Effect context."
`;

0 comments on commit bac42aa

Please sign in to comment.