diff --git a/docs/typescript-examples/func.ts b/docs/typescript-examples/func.ts index 42e5d1b..8d56034 100644 --- a/docs/typescript-examples/func.ts +++ b/docs/typescript-examples/func.ts @@ -30,16 +30,17 @@ const block_1 = de.func( { }; }, options: { + error: () => { + return { + x: 1 + } + }, params: ( { params }: { params: ParamsIn1 } ) => { return { s1: params.id, }; }, - // Важно!!! - // Необходимо задать тип входящего result'а именно здесь. - // Почему-то этот тип не берется из результата функции из block. - // after: ( { params, result }) => { console.log( params ); return { @@ -64,7 +65,7 @@ const block_2 = de.func({ return Promise.resolve(result); }, options: { - after: ({ result }): string => { + after: ({ result }) => { return result.foo; }, }, @@ -74,3 +75,21 @@ de.run( block_2, {} ) .then( ( result ) => { console.log( result ); }); + +const block3 = block_2({ + options: { + after: ({ result }) => { + console.log(result); + + return { + res: result, + } + }, + } +}) + + +de.run( block3, {} ) + .then( ( result ) => { + console.log( result ); + }); diff --git a/docs/typescript-examples/http.ts b/docs/typescript-examples/http.ts index 418f161..42f1cf7 100644 --- a/docs/typescript-examples/http.ts +++ b/docs/typescript-examples/http.ts @@ -65,6 +65,16 @@ const block1 = de.http( { }, options: ({ + before: () => { + return { + d: 1 + } + }, + error: () => { + return { + x: 's' + } + }, params: ( { params }: { params: ParamsIn1 }) => { return { s1: params.id_1, diff --git a/docs/typescript-examples/object.ts b/docs/typescript-examples/object.ts index cecbb96..2199a8f 100644 --- a/docs/typescript-examples/object.ts +++ b/docs/typescript-examples/object.ts @@ -10,24 +10,49 @@ interface Context { } // --------------------------------------------------------------------------------------------------------------- // +export interface CreateCardRequest { + added_manually?: boolean; + added_by_identifier?: string; + // card: Card; + card: Record; +} interface ParamsIn1 { id_1: string; + payload: CreateCardRequest; +} +interface ParamsOut1 { + s1: string; +} +interface Result1 { + r: number; } const block_1 = de.http( { - block: {}, + block: { + body: ({ params }) => params.payload, + }, options: { params: ( { params }: { params: ParamsIn1, context: Context } ) => { return { s1: params.id_1, + payload: params.payload }; }, - after: ( { params, context } ) => { - return { - a: params.s1, + after: ( { params, context, result }: { params: ParamsOut1, context: Context, result: Result1 } ) => { + const a = { + a: 1, }; + const b = { + b: params.s1, + } + + if (params.s1 === 'lol') { + return a; + } + + return b; }, }, } ); @@ -36,12 +61,15 @@ const block_1 = de.http( { de.run( block_1, { params: { id_1: '67890', + payload: { + card: {} + } }, } ) .then( ( result ) => { console.log( result ); return { - foo: result.a, + foo: 'a' in result ? result.a : result.b, bar: undefined, }; } ); @@ -138,6 +166,9 @@ de.run( block_3, { params: { id_1: '12345', id_2: 67890, + payload: { + card: {} + } }, } ) .then( ( result ) => { @@ -166,6 +197,9 @@ de.run( block_3_func, { params: { id_1: '12345', id_2: 67890, + payload: { + card: {} + } }, } ) .then( ( result ) => { @@ -180,10 +214,24 @@ const block_4 = block_3( { }, } ); +const block_5 = block_3( { + options: { + error: ({ cancel, error }) => { + if (error.error) { + throw error; + } + }, + after: ( { result } ) => result, + }, +} ); + de.run( block_4, { params: { id_1: '12345', id_2: 67890, + payload: { + card: {} + } }, } ) .then( ( result ) => { diff --git a/docs/typescript-examples/session.ts b/docs/typescript-examples/session.ts index fc2597d..4760d82 100644 --- a/docs/typescript-examples/session.ts +++ b/docs/typescript-examples/session.ts @@ -133,6 +133,7 @@ const sessionMethod = de.func({ }, after: ({context, params, result}) => { + const x = result; const session = result.session as Session & Record; return session; diff --git a/lib/index.d.ts b/lib/index.d.ts index bc11cc0..86b9f2b 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -16,11 +16,11 @@ type UnionToIntersection< U > = ( ( k: infer I ) => void ) ? I : never; -type InferContext = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer ResultOut > ? Context : never; -type InferParamsIn = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer ResultOut > ? ParamsIn : never; -type InferParamsOut = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer ResultOut > ? ParamsOut : never; -type InferResultIn = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer ResultOut > ? ResultIn : never; -type InferResultOut = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer ResultOut > ? ResultOut : never; +type InferContext = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? Context : never; +type InferParamsIn = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? ParamsIn : never; +type InferParamsOut = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? ParamsOut : never; +type InferResultIn = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? ResultIn : never; +type InferResultOut = Type extends DescriptBlock< infer Context, infer ParamsIn, infer ResultIn, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? ResultOut : never; type DescriptBlockParams = { @@ -39,16 +39,17 @@ type DescriptBlockResult = { type GetDescriptBlockResultIn = T extends DescriptBlockResult ? ResultIn : T; type GetDescriptBlockResultOut = T extends DescriptBlockResult ? ResultOut : T; -type InferResultInFromBlockOrReturnResultIn = Type extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer ResultOut > ? Result : Type; -type InferResultOutFromBlockOrReturnResultOut = Type extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer ResultOut > ? ResultOut : Type; -type InferParamsFromBlockOrReturnParams = Block extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer ResultOut > ? ParamsIn : Params; +type InferResultInFromBlockOrReturnResultIn = Type extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? Result : Type; +type InferResultOutFromBlockOrReturnResultOut = Type extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? ResultOut : Type; +type InferParamsFromBlockOrReturnParams = Block extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? ParamsIn : Params; -type InferResultInFromBlocks = Block extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer ResultOut > ? +type InferResultInFromBlocks = Block extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? { [ K in keyof Result ]: InferResultInFromBlocks } : Block; +type NotUnknown = NonNullable; -type InferResultOutFromBlocks = Block extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer ResultOut > ? +type InferResultOutFromBlocks = Block extends DescriptBlock< infer Context, infer ParamsIn, infer Result, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? { [ K in keyof ResultOut ]: InferResultOutFromBlocks } : Block; @@ -70,6 +71,7 @@ type DescriptJSON = undefined | null | { [ property: string ]: DescriptJSON } | + object | Array< DescriptJSON >; // --------------------------------------------------------------------------------------------------------------- // @@ -163,12 +165,18 @@ type DescriptBlockGenerateId = () => DescriptBlockId; type DescriptBlockDeps = Record< DescriptBlockId, any >; +type ComplexResult = Result | GetDescriptBlockResultOut | Promise< Result | GetDescriptBlockResultOut > | void | null; + interface DescriptBlockOptions< Context, Params, ResultIn, ParamsOut = Params, - ResultOut = ResultIn, + BeforeResultOut = ResultIn, + ErrorResultOut = ResultIn, + AfterResultIn = ResultIn, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, > { name?: string; @@ -186,15 +194,15 @@ interface DescriptBlockOptions< context: Context, deps: DescriptBlockDeps, cancel: Cancel, - } ) => ResultOut | Promise | undefined | void; + } ) => ComplexResult after?: ( args: { params: ParamsOut, context: Context, deps: DescriptBlockDeps, cancel: Cancel, - result: ResultIn, - } ) => ResultOut | Promise< ResultOut >; + result: AfterResultIn, + } ) => ComplexResult error?: ( args: { params: ParamsOut, @@ -202,7 +210,7 @@ interface DescriptBlockOptions< deps: DescriptBlockDeps, cancel: Cancel, error: DescriptError, - } ) => ResultOut | void; + } ) => ComplexResult timeout?: number; @@ -212,7 +220,7 @@ interface DescriptBlockOptions< deps: DescriptBlockDeps, } ) => string ); maxage?: number; - cache?: Cache< ResultOut, Context >; + cache?: Cache< ResultOut | GetDescriptBlockResultOut, Context >; required?: boolean; @@ -325,16 +333,34 @@ interface DescriptHttpBlock< Params, Result, ParamsOut = Params, - ResultOut = Result, + BeforeResultOut = undefined, + ErrorResultOut = undefined, + AfterResultIn = Result, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, > { < ExtendedParams = Params, ExtendedResult = Result, ExtendedParamsOut = ExtendedParams, - ExtendedResultOut = ExtendedResult, + ExtendedBeforeResultOut = undefined, + ExtendedErrorResultOut = undefined, + ExtendedAfterResultIn = ExtendedResult, + ExtendedAfterResultOut = ExtendedAfterResultIn, + ExtendedResultOut = Exclude, >( args: { block?: DescriptHttpBlockDescription< GetDescriptBlockParamsFnOut, Context >, - options?: DescriptBlockOptions< Context, GetDescriptBlockParamsFnIn, GetDescriptBlockResultIn, GetDescriptBlockParamsFnOut, GetDescriptBlockResultOut >, + options?: DescriptBlockOptions< + Context, + GetDescriptBlockParamsFnIn, + GetDescriptBlockResultIn, + GetDescriptBlockParamsFnOut, + ExtendedBeforeResultOut, + ExtendedErrorResultOut, + GetDescriptBlockResultIn, + ExtendedAfterResultOut, + ExtendedResultOut + >, } ): DescriptHttpBlock< Context, DescriptBlockParams, GetDescriptBlockParamsFnOut>, @@ -347,11 +373,25 @@ declare function http< Params, Result, ParamsOut = Params, - ResultOut = Result, + BeforeResultOut = undefined, + ErrorResultOut = undefined, + AfterResultIn = Result, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, > ( args: { block: DescriptHttpBlockDescription< GetDescriptBlockParamsFnOut, Context >, - options?: DescriptBlockOptions< Context, GetDescriptBlockParamsFnIn, GetDescriptBlockResultIn, GetDescriptBlockParamsFnOut, GetDescriptBlockResultOut >, + options?: DescriptBlockOptions< + Context, + GetDescriptBlockParamsFnIn, + GetDescriptBlockResultIn, + GetDescriptBlockParamsFnOut, + BeforeResultOut, + ErrorResultOut, + GetDescriptBlockResultIn, + AfterResultOut, + ResultOut + >, }, ): DescriptHttpBlock< Context, @@ -381,13 +421,21 @@ interface DescriptFuncBlock< Params, Result, ParamsOut = Params, - ResultOut = Result, + BeforeResultOut = undefined, + ErrorResultOut = undefined, + AfterResultIn = Result, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, > { < ExtendedParams = Params, ExtendedResult = Result, ExtendedParamsOut = ExtendedParams, - ExtendedResultOut = ExtendedResult, + ExtendedBeforeResultOut = undefined, + ExtendedErrorResultOut = undefined, + ExtendedAfterResultIn = ExtendedResult, + ExtendedAfterResultOut = ExtendedAfterResultIn, + ExtendedResultOut = ExtendedBeforeResultOut | ExtendedErrorResultOut | ExtendedAfterResultOut, >( args: { block?: DescriptFuncBlockDescription< Context, GetDescriptBlockParamsFnOut, GetDescriptBlockResultIn>, options?: DescriptBlockOptions< @@ -395,7 +443,11 @@ interface DescriptFuncBlock< GetDescriptBlockParamsFnIn, GetDescriptBlockResultIn>, GetDescriptBlockParamsFnOut, - GetDescriptBlockResultOut + ExtendedBeforeResultOut, + ExtendedErrorResultOut, + GetDescriptBlockResultIn>, + ExtendedAfterResultOut, + ExtendedResultOut >, } ): DescriptFuncBlock< Context, DescriptBlockParams>, GetDescriptBlockParamsFnOut>>, @@ -406,22 +458,30 @@ interface DescriptFuncBlock< declare function func< Context, Params, - Result, + ResultIn, ParamsOut = Params, - ResultOut = Result, + BeforeResultOut = undefined, + ErrorResultOut = undefined, + AfterResultIn = ResultIn, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, > ( args: { - block: DescriptFuncBlockDescription< Context, GetDescriptBlockParamsFnOut, GetDescriptBlockResultIn >, + block: DescriptFuncBlockDescription< Context, GetDescriptBlockParamsFnOut, GetDescriptBlockResultIn >, options?: DescriptBlockOptions< Context, GetDescriptBlockParamsFnIn, - GetDescriptBlockResultIn>, + GetDescriptBlockResultIn>, GetDescriptBlockParamsFnOut, - GetDescriptBlockResultOut> + BeforeResultOut, + ErrorResultOut, + GetDescriptBlockResultIn>, + AfterResultOut, + ResultOut >, }, ): DescriptFuncBlock< Context, - DescriptBlockParams>, GetDescriptBlockParamsFnOut>>, + DescriptBlockParams>, GetDescriptBlockParamsFnOut>>, GetDescriptBlockResultOut> >; @@ -447,7 +507,7 @@ type GetArrayBlockContext< T > = { }[ T extends [] ? 0 : T extends ( ( readonly [ any ] ) | [ any ] ) ? 1 : 2 ]; type DescriptArrayBlockDescription< T > = { - [ P in keyof T ]: T[ P ] extends DescriptBlock< infer Context, infer Params, infer Result > ? T[ P ] : never + [ P in keyof T ]: T[ P ] extends DescriptBlock< infer Context, infer Params, infer ResultIn, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer Result > ? T[ P ] : never } interface DescriptArrayBlock< @@ -455,15 +515,33 @@ interface DescriptArrayBlock< Params, ResultIn, ParamsOut = Params, - ResultOut = ResultIn, + BeforeResultOut = undefined, + ErrorResultOut = undefined, + AfterResultIn = ResultIn, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, > { < ExtendedParams = Params, ExtendedResultIn = ResultIn, ExtendedParamsOut = ExtendedParams, - ExtendedResultOut = ResultOut, + ExtendedBeforeResultOut = undefined, + ExtendedErrorResultOut = undefined, + ExtendedAfterResultIn = ExtendedResultIn, + ExtendedAfterResultOut = ExtendedAfterResultIn, + ExtendedResultOut = Exclude, >( args: { - options?: DescriptBlockOptions< Context, GetDescriptBlockParamsFnIn, ExtendedResultIn, GetDescriptBlockParamsFnOut, ExtendedResultOut >, + options?: DescriptBlockOptions< + Context, + GetDescriptBlockParamsFnIn, + ExtendedResultIn, + GetDescriptBlockParamsFnOut, + ExtendedBeforeResultOut, + ExtendedErrorResultOut, + ExtendedAfterResultIn, + ExtendedAfterResultOut, + ExtendedResultOut + >, } ): DescriptArrayBlock< Context, DescriptBlockParams, GetDescriptBlockParamsFnOut>, @@ -477,7 +555,11 @@ declare function array< Params = GetArrayBlockParams< Block >, ResultIn = GetArrayBlockResult< Block >, ParamsOut = Params, - ResultOut = ResultIn, + BeforeResultOut = undefined, + ErrorResultOut = undefined, + AfterResultIn = GetArrayBlockResult< Block >, + AfterResultOut = GetArrayBlockResult< Block >, + ResultOut = Exclude, > ( args: { block: DescriptArrayBlockDescription< Block >, @@ -486,6 +568,10 @@ declare function array< GetDescriptBlockParamsFnIn, ResultIn, GetDescriptBlockParamsFnOut, + BeforeResultOut, + ErrorResultOut, + AfterResultIn, + AfterResultOut, ResultOut >, }, @@ -538,11 +624,11 @@ type GetObjectBlockContextMap< T extends {} > = { type GetObjectBlockContext< T extends {}, M = GetObjectBlockContextMap< T > > = UnionToIntersection< M[ keyof M ] >; type DescriptObjectBlockDescription< T extends {} > = { - [ P in keyof T ]: T[ P ] extends DescriptBlock< infer Context, infer Params, infer ResultIn, infer ParamsOut, infer ResultOut > ? T[ P ] : never + [ P in keyof T ]: T[ P ] extends DescriptBlock< infer Context, infer Params, infer ResultIn, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? T[ P ] : never } type DescriptObjectBlockDescriptionResults< T extends {} > = { - [ P in keyof T ]: T[ P ] extends DescriptBlock< infer Context, infer Params, infer ResultIn, infer ParamsOut, infer ResultOut > ? ResultOut : never + [ P in keyof T ]: T[ P ] extends DescriptBlock< infer Context, infer Params, infer ResultIn, infer ParamsOut, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer ResultOut > ? ResultOut : never } interface DescriptObjectBlock< @@ -550,25 +636,37 @@ interface DescriptObjectBlock< Params, ResultIn, ParamsOut = Params, - ResultOut = ResultIn, + BeforeResultOut = undefined, + ErrorResultOut = undefined, + AfterResultIn = ResultIn, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, > { < ExtendedParams = Params, ExtendedResultIn = ResultIn, ExtendedParamsOut = ExtendedParams, - ExtendedResultOut = ResultOut, + ExtendedBeforeResultOut = undefined, + ExtendedErrorResultOut = undefined, + ExtendedAfterResultIn = ExtendedResultIn, + ExtendedAfterResultOut = ExtendedAfterResultIn, + ExtendedResultOut = Exclude, >( args: { options?: DescriptBlockOptions< Context, GetDescriptBlockParamsFnIn, GetDescriptBlockResultIn>, GetDescriptBlockParamsFnOut, - GetDescriptBlockResultOut> + ExtendedBeforeResultOut, + ExtendedErrorResultOut, + ExtendedAfterResultIn, + ExtendedAfterResultOut, + ExtendedResultOut >, } ): DescriptObjectBlock< Context, DescriptBlockParams, GetDescriptBlockParamsFnOut>, - GetDescriptBlockResultOut> + GetDescriptBlockResultOut> >; } @@ -578,7 +676,12 @@ declare function object< Params = GetObjectBlockParams< Block >, ResultIn = GetObjectBlockResultIn< Block >, ParamsOut = Params, - ResultOut = GetObjectBlockResultOut, + //ResultOut = GetObjectBlockResultOut, + BeforeResultOut = undefined, + ErrorResultOut = undefined, + AfterResultIn = GetObjectBlockResultOut, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, > ( args: { block: DescriptObjectBlockDescription< Block >, @@ -587,7 +690,16 @@ declare function object< GetDescriptBlockParamsFnIn, GetDescriptBlockResultIn>, GetDescriptBlockParamsFnOut, - GetDescriptBlockResultOut> + BeforeResultOut, + ErrorResultOut, + GetDescriptBlockResultIn>, + AfterResultOut, + ResultOut + /*GetDescriptBlockResultIn>, + GetDescriptBlockResultIn>, + GetDescriptBlockResultIn>, + InferResultOutFromBlocks, + InferResultOutFromBlocks*/ >, }, ): DescriptObjectBlock< @@ -618,22 +730,22 @@ interface DescriptFirstBlock { */ -type DescriptBlock< Context, Params, Result, ParamsOut = Params, ResultOut = Result > = - DescriptHttpBlock< Context, Params, Result, ParamsOut, ResultOut > | - DescriptFuncBlock< Context, Params, Result, ParamsOut, ResultOut > | - DescriptArrayBlock< Context, Params, Result, ParamsOut, ResultOut > | - DescriptObjectBlock< Context, Params, Result, ParamsOut, ResultOut >; +type DescriptBlock< Context, Params, Result, ParamsOut = Params, BeforeResultOut = Result, ErrorResultOut = Result, AfterResultIn = Result, AfterResultOut = Result, ResultOut = BeforeResultOut | ErrorResultOut | AfterResultOut > = + DescriptHttpBlock< Context, Params, Result, ParamsOut, BeforeResultOut, ErrorResultOut, AfterResultIn, AfterResultOut, ResultOut > | + DescriptFuncBlock< Context, Params, Result, ParamsOut, BeforeResultOut, ErrorResultOut, AfterResultIn, AfterResultOut, ResultOut > | + DescriptArrayBlock< Context, Params, Result, ParamsOut, BeforeResultOut, ErrorResultOut, AfterResultIn, AfterResultOut, ResultOut > | + DescriptObjectBlock< Context, Params, Result, ParamsOut, BeforeResultOut, ErrorResultOut, AfterResultIn, AfterResultOut, ResultOut >; // --------------------------------------------------------------------------------------------------------------- // export type GetDescriptBlockResult< T > = - T extends DescriptBlock< infer Context, infer Params, infer Result > ? Result : never; + T extends DescriptBlock< infer Context, infer Params, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer Result > ? Result : never; export type GetDescriptBlockParams< T > = - T extends DescriptBlock< infer Context, infer Params, infer Result > ? Params : never; + T extends DescriptBlock< infer Context, infer Params, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer Result > ? Params : never; export type GetDescriptBlockContext< T > = - T extends DescriptBlock< infer Context, infer Params, infer Result > ? Context : never; + T extends DescriptBlock< infer Context, infer Params, infer BeforeResultOut, infer ErrorResultOut, infer AfterResultIn, infer AfterResultOut, infer Result > ? Context : never; // --------------------------------------------------------------------------------------------------------------- // @@ -642,14 +754,22 @@ declare function run< Params, Result, ParamsOut = Params, - ResultOut = Result, + BeforeResultOut = undefined, + ErrorResultOut = undefined, + AfterResultIn = Result, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, > ( block: DescriptBlock< Context, GetDescriptBlockParamsFnIn, GetDescriptBlockResultIn>, GetDescriptBlockParamsFnOut, - GetDescriptBlockResultOut> + BeforeResultOut, + ErrorResultOut, + AfterResultIn, + AfterResultOut, + ResultOut >, args: { params?: GetDescriptBlockParamsBlock, @@ -698,4 +818,14 @@ declare namespace request { } -declare function inferBlockTypes< Context, Params, Result, ParamsOut = Params, ResultOut = Result >(block: DescriptBlock): DescriptBlock; +declare function inferBlockTypes< + Context, + Params, + ResultIn, + ParamsOut = Params, + BeforeResultOut = ResultIn, + ErrorResultOut = ResultIn, + AfterResultIn = ResultIn, + AfterResultOut = AfterResultIn, + ResultOut = Exclude, +>(block: DescriptBlock): typeof block;