diff --git a/src/types/actions/index.ts b/src/types/actions/index.ts index 5c7e7841a..239cf7f0a 100644 --- a/src/types/actions/index.ts +++ b/src/types/actions/index.ts @@ -35,22 +35,30 @@ export type SlackAction = BlockAction | InteractiveMessage | DialogSubmitAction * `BlockAction` can be used to create a type for this parameter based on an element's action type. In * this case `ElementAction` must extend `BasicElementAction`. */ -export interface SlackActionMiddlewareArgs { +export type SlackActionMiddlewareArgs = { payload: Action extends BlockAction ? ElementAction : Action extends InteractiveMessage ? InteractiveAction : Action; - action: this['payload']; + // too bad we can't use `this['payload']` in a type (as opposed to interface) but the use of `& unknown` below is too useful + action: Action extends BlockAction + ? ElementAction + : Action extends InteractiveMessage + ? InteractiveAction + : Action; body: Action; - // all action types except dialog submission have a channel context - say: Action extends Exclude ? SayFn : undefined; respond: RespondFn; ack: ActionAckFn; + // TODO: can we conditionally apply these custom-function-specific properties only in certain situations? how can we get function-scoped interactivity events included in the generics? complete?: FunctionCompleteFn; fail?: FunctionFailFn; inputs?: FunctionInputs; -} +} & (Action extends Exclude + // all action types except dialog submission and steps from apps have a channel context + ? { say: SayFn } + : unknown +); /** * Type function which given an action `A` returns a corresponding type for the `ack()` function. The function is used