|
| 1 | +/// <reference path="fourslash.ts" /> |
| 2 | + |
| 3 | +// @strict: true |
| 4 | +// @target: esnext |
| 5 | +// @lib: esnext |
| 6 | + |
| 7 | +//// export interface Pipeable { |
| 8 | +//// pipe<A, B = never>(this: A, ab: (_: A) => B): B; |
| 9 | +//// } |
| 10 | +//// |
| 11 | +//// type Covariant<A> = (_: never) => A; |
| 12 | +//// |
| 13 | +//// interface VarianceStruct<out A, out E, out R> { |
| 14 | +//// readonly _V: string; |
| 15 | +//// readonly _A: Covariant<A>; |
| 16 | +//// readonly _E: Covariant<E>; |
| 17 | +//// readonly _R: Covariant<R>; |
| 18 | +//// } |
| 19 | +//// |
| 20 | +//// declare const EffectTypeId: unique symbol; |
| 21 | +//// |
| 22 | +//// interface Variance<out A, out E, out R> { |
| 23 | +//// readonly [EffectTypeId]: VarianceStruct<A, E, R>; |
| 24 | +//// } |
| 25 | +//// |
| 26 | +//// interface Effect<out A, out E = never, out R = never> |
| 27 | +//// extends Variance<A, E, R>, |
| 28 | +//// Pipeable {} |
| 29 | +//// |
| 30 | +//// interface Class<Fields> extends Pipeable { |
| 31 | +//// new (): Fields; |
| 32 | +//// } |
| 33 | +//// |
| 34 | +//// interface TaggedErrorClass<Tag extends string, Fields> extends Class<Fields> { |
| 35 | +//// readonly _tag: Tag; |
| 36 | +//// } |
| 37 | +//// |
| 38 | +//// declare const TaggedError: (identifier?: string) => < |
| 39 | +//// Tag extends string, |
| 40 | +//// Fields |
| 41 | +//// >( |
| 42 | +//// tag: Tag, |
| 43 | +//// fieldsOr: Fields |
| 44 | +//// ) => TaggedErrorClass< |
| 45 | +//// Tag, |
| 46 | +//// { |
| 47 | +//// readonly _tag: Tag; |
| 48 | +//// } |
| 49 | +//// >; |
| 50 | +//// |
| 51 | +//// declare const log: ( |
| 52 | +//// ...message: ReadonlyArray<any> |
| 53 | +//// ) => Effect<void, never, never>; |
| 54 | +//// |
| 55 | +//// export const categoriesKey = "@effect/error/categories"; |
| 56 | +//// |
| 57 | +//// export declare const withCategory: <Categories extends Array<PropertyKey>>( |
| 58 | +//// ...categories: Categories |
| 59 | +//// ) => <Args extends Array<any>, Ret, C extends { new (...args: Args): Ret }>( |
| 60 | +//// C: C |
| 61 | +//// ) => C & { |
| 62 | +//// new (...args: Args): Ret & { |
| 63 | +//// [categoriesKey]: { [Cat in Categories[number]]: true }; |
| 64 | +//// }; |
| 65 | +//// }; |
| 66 | +//// |
| 67 | +//// export type AllKeys<E> = E extends { [categoriesKey]: infer Q } |
| 68 | +//// ? keyof Q |
| 69 | +//// : never; |
| 70 | +//// export type ExtractAll<E, Cats extends PropertyKey> = Cats extends any |
| 71 | +//// ? Extract<E, { [categoriesKey]: { [K in Cats]: any } }> |
| 72 | +//// : never; |
| 73 | +//// |
| 74 | +//// export declare const catchCategory: < |
| 75 | +//// E, |
| 76 | +//// const Categories extends Array<AllKeys<E>>, |
| 77 | +//// A2, |
| 78 | +//// E2, |
| 79 | +//// R2 |
| 80 | +//// >( |
| 81 | +//// ...args: [ |
| 82 | +//// ...Categories, |
| 83 | +//// f: (err: ExtractAll<E, Categories[number]>) => Effect<A2, E2, R2> |
| 84 | +//// ] |
| 85 | +//// ) => <A, R>( |
| 86 | +//// effect: Effect<A, E, R> |
| 87 | +//// ) => Effect<A | A2, E2 | Exclude<E, ExtractAll<E, Categories[number]>>, R | R2>; |
| 88 | +//// |
| 89 | +//// class FooError extends TaggedError()("FooError", {}).pipe( |
| 90 | +//// withCategory("domain") |
| 91 | +//// ) {} |
| 92 | +//// |
| 93 | +//// class BarError extends TaggedError()("BarError", {}).pipe( |
| 94 | +//// withCategory("system", "domain") |
| 95 | +//// ) {} |
| 96 | +//// |
| 97 | +//// class BazError extends TaggedError()("BazError", {}).pipe( |
| 98 | +//// withCategory("system") |
| 99 | +//// ) {} |
| 100 | +//// |
| 101 | +//// declare const baz: ( |
| 102 | +//// x: number |
| 103 | +//// ) => Effect<never, FooError | BarError | BazError, never>; |
| 104 | +//// |
| 105 | +//// export const program = baz(1).pipe(catchCategory("domain",/*1*/ (_) => log(_._tag))); |
| 106 | + |
| 107 | +verify.noErrors(); |
| 108 | +goTo.marker("1"); |
| 109 | +edit.insert(","); |
| 110 | +verify.signatureHelpPresentForTriggerReason({ |
| 111 | + kind: "characterTyped", |
| 112 | + triggerCharacter: ",", |
| 113 | +}); |
| 114 | +edit.backspace(1); |
| 115 | +verify.signatureHelpPresentForTriggerReason({ |
| 116 | + kind: "retrigger", |
| 117 | +}); |
| 118 | +verify.noErrors(); |
0 commit comments