Skip to content

Commit

Permalink
linting progress on tests, trying to eliminate some anys.
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Maj committed Sep 16, 2024
1 parent 100930d commit 82b5794
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
22 changes: 11 additions & 11 deletions src/App-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,11 @@ describe('App event routing', () => {

const callNextMiddleware =
() =>
async ({ next }: { next?: NextFn }) => {
if (next) {
await next();
}
};
async ({ next }: { next?: NextFn }) => {
if (next) {
await next();
}
};

const fakeMessageEvent = (receiver: FakeReceiver, message: string): Promise<void> =>
receiver.sendEvent({
Expand All @@ -861,11 +861,11 @@ describe('App event routing', () => {

const controlledMiddleware =
(shouldCallNext: boolean) =>
async ({ next }: { next?: NextFn }) => {
if (next && shouldCallNext) {
await next();
}
};
async ({ next }: { next?: NextFn }) => {
if (next && shouldCallNext) {
await next();
}
};

const assertMiddlewaresCalledOnce = () => {
assert(fakeMiddleware1.calledOnce);
Expand Down Expand Up @@ -1078,7 +1078,7 @@ async function importApp(
function withNoopWebClient(): Override {
return {
'@slack/web-api': {
WebClient: class { },
WebClient: class {},
},
};
}
Expand Down
34 changes: 17 additions & 17 deletions src/WorkflowStep.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { WorkflowStepExecuteEvent } from '@slack/types';
import type {
Block,
Expand Down Expand Up @@ -32,15 +31,16 @@ export interface StepConfigureArguments {
}

export interface StepUpdateArguments {
inputs?: {
[key: string]: {
inputs?: Record<
string,
{
// biome-ignore lint/suspicious/noExplicitAny: user-defined workflow inputs could be anything
value: any;
skip_variable_replacement?: boolean;
variables?: {
[key: string]: any;
};
};
};
// biome-ignore lint/suspicious/noExplicitAny: user-defined workflow inputs could be anything
variables?: Record<string, any>;
}
>;
outputs?: {
name: string;
type: string;
Expand All @@ -51,9 +51,8 @@ export interface StepUpdateArguments {
}

export interface StepCompleteArguments {
outputs?: {
[key: string]: any;
};
// biome-ignore lint/suspicious/noExplicitAny: user-defined workflow outputs could be anything
outputs?: Record<string, any>;
}

export interface StepFailArguments {
Expand Down Expand Up @@ -142,7 +141,7 @@ export class WorkflowStep {
}

public getMiddleware(): Middleware<AnyMiddlewareArgs> {
return async (args): Promise<any> => {
return async (args): Promise<void> => {
if (isStepEvent(args) && this.matchesConstraints(args)) {
return this.processEvent(args);
}
Expand Down Expand Up @@ -193,11 +192,11 @@ export function validate(callbackId: string, config: WorkflowStepConfig): void {
// Check for missing required keys
const requiredKeys: (keyof WorkflowStepConfig)[] = ['save', 'edit', 'execute'];
const missingKeys: (keyof WorkflowStepConfig)[] = [];
requiredKeys.forEach((key) => {
for (const key of requiredKeys) {
if (config[key] === undefined) {
missingKeys.push(key);
}
});
}

if (missingKeys.length > 0) {
const errorMsg = `WorkflowStep is missing required keys: ${missingKeys.join(', ')}`;
Expand All @@ -206,12 +205,12 @@ export function validate(callbackId: string, config: WorkflowStepConfig): void {

// Ensure a callback or an array of callbacks is present
const requiredFns: (keyof WorkflowStepConfig)[] = ['save', 'edit', 'execute'];
requiredFns.forEach((fn) => {
for (const fn of requiredFns) {
if (typeof config[fn] !== 'function' && !Array.isArray(config[fn])) {
const errorMsg = `WorkflowStep ${fn} property must be a function or an array of functions`;
throw new WorkflowStepInitializationError(errorMsg);
}
});
}
}

/**
Expand Down Expand Up @@ -341,8 +340,9 @@ function createStepFail(args: AllWorkflowStepMiddlewareArgs<WorkflowStepExecuteM
* 2. augments args with step lifecycle-specific properties/utilities
* */
// TODO :: refactor to incorporate a generic parameter
export function prepareStepArgs(args: any): AllWorkflowStepMiddlewareArgs {
export function prepareStepArgs(args: AllWorkflowStepMiddlewareArgs): AllWorkflowStepMiddlewareArgs {
const { next: _next, ...stepArgs } = args;
// biome-ignore lint/suspicious/noExplicitAny: need to use any as the cases of the switch that follows dont narrow to the specific required args type. use type predicates for each workflow_step event args in the switch to get rid of this any.
const preparedArgs: any = { ...stepArgs };

switch (preparedArgs.payload.type) {
Expand Down

0 comments on commit 82b5794

Please sign in to comment.