Skip to content

Commit dfd3e57

Browse files
committed
fix: fix types
1 parent 205c2d8 commit dfd3e57

File tree

2 files changed

+52
-28
lines changed

2 files changed

+52
-28
lines changed

lib/components/TaskTesting/TaskTesting.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ import '../../style/style.scss';
3434
import { PluginContext, usePluginsProviderValue } from '../shared/plugins';
3535
import { OutputTab } from '../Output/OutputVariables';
3636

37+
/**
38+
* @param {import('../../types').TaskExecutionResult} result
39+
* @returns {result is import('../../types').TaskExecutionIncidentResult}
40+
*/
41+
function isIncidentResult(result) {
42+
return !result.success && result.reason === TASK_EXECUTION_REASON.INCIDENT;
43+
}
44+
45+
/**
46+
* @param {import('../../types').TaskExecutionResult} result
47+
* @returns {result is import('../../types').TaskExecutionErrorResult}
48+
*/
49+
function isErrorResult(result) {
50+
return !result.success && result.reason === TASK_EXECUTION_REASON.ERROR;
51+
}
52+
3753
/**
3854
* @param {Object} props
3955
* @param {Object} props.injector
@@ -230,14 +246,14 @@ export default function TaskTesting({
230246
variables: result.variables,
231247
operateUrl: currentOperateUrl
232248
});
233-
} else if (result.reason === TASK_EXECUTION_REASON.INCIDENT) {
249+
} else if (isIncidentResult(result)) {
234250
elementConfigRef?.current?.setOutputConfigForElement(element, {
235251
success: false,
236252
variables: result.variables,
237253
incident: result.incident,
238254
operateUrl: currentOperateUrl
239255
});
240-
} else if (result.reason === TASK_EXECUTION_REASON.ERROR) {
256+
} else if (isErrorResult(result)) {
241257
elementConfigRef?.current?.setOutputConfigForElement(element, {
242258
success: false,
243259
error: result.error

lib/types.d.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,32 +81,40 @@ export type TaskExecutionEvents =
8181
'taskExecution.status.changed' |
8282
'taskExecution.finished';
8383

84-
export type TaskExecutionResult =
85-
// Success case - no reason needed
86-
| {
87-
success: true;
88-
variables: ElementOutputVariables;
89-
}
90-
// Failure cases - always have reason
91-
| {
92-
success: false;
93-
reason: typeof TASK_EXECUTION_REASON.INCIDENT;
94-
incident: any;
95-
variables?: ElementOutputVariables;
96-
}
97-
| {
98-
success: false;
99-
reason: typeof TASK_EXECUTION_REASON.USER_CANCEL;
100-
}
101-
| {
102-
success: false;
103-
reason: typeof TASK_EXECUTION_REASON.USER_SELECTION_CHANGED;
104-
}
105-
| {
106-
success: false;
107-
reason: typeof TASK_EXECUTION_REASON.ERROR;
108-
error: TaskExecutionError;
109-
};
84+
export type TaskExecutionSuccessResult = {
85+
success: true;
86+
variables: ElementOutputVariables;
87+
};
88+
89+
export type TaskExecutionIncidentResult = {
90+
success: false;
91+
reason: typeof TASK_EXECUTION_REASON.INCIDENT;
92+
incident: any;
93+
variables?: ElementOutputVariables;
94+
};
95+
96+
export type TaskExecutionUserCancelResult = {
97+
success: false;
98+
reason: typeof TASK_EXECUTION_REASON.USER_CANCEL;
99+
};
100+
101+
export type TaskExecutionUserSelectionChangedResult = {
102+
success: false;
103+
reason: typeof TASK_EXECUTION_REASON.USER_SELECTION_CHANGED;
104+
};
105+
106+
export type TaskExecutionErrorResult = {
107+
success: false;
108+
reason: typeof TASK_EXECUTION_REASON.ERROR;
109+
error: TaskExecutionError;
110+
};
111+
112+
export type TaskExecutionResult =
113+
| TaskExecutionSuccessResult
114+
| TaskExecutionIncidentResult
115+
| TaskExecutionUserCancelResult
116+
| TaskExecutionUserSelectionChangedResult
117+
| TaskExecutionErrorResult;
110118

111119
export type TaskExecutionError = {
112120
message: string;

0 commit comments

Comments
 (0)