1 ---
2 sidebar_label: "no-spread-in-workflow"
3 ---
4
5 export const metadata = {
6 title: `no-spread-in-workflow - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 This rule disallows spread (`...`) and rest (`...`) elements directly inside a `createWorkflow` constructor or a `when().then()` callback.
12
13 ## Severity
14
15 `error`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset.
16
17 ## What it Targets
18
19 This rule targets files in your project's `src/workflows` directory. It reports spread and rest elements placed directly in a workflow's constructor or in a `when().then()` callback.
20
21 The following code is reported by the rule:
22
23 ```ts title="src/workflows/example.ts"
24 import {
25 createWorkflow,
26 WorkflowResponse,
27 } from "@medusajs/framework/workflows-sdk"
28
29 createWorkflow("my-workflow", (input) => {
30 const merged = { ...input, extra: 1 }
31 return new WorkflowResponse(merged)
32 })
33 ```
34
35 Instead, wrap object or array manipulation in `transform`:
36
37 ```ts title="src/workflows/example.ts"
38 import {
39 createWorkflow,
40 transform,
41 WorkflowResponse,
42 } from "@medusajs/framework/workflows-sdk"
43
44 createWorkflow("my-workflow", (input) => {
45 const merged = transform({ input }, (data) => {
46 return { ...data.input, extra: 1 }
47 })
48
49 return new WorkflowResponse(merged)
50 })
51 ```
52
53 ## Why it's Important
54
55 A workflow's constructor and `when().then()` callbacks run at definition time, not execution time. So, the spread or rest evaluates against placeholder values rather than the real data. Move the operation into `transform` or a `createStep` callback so it runs at execution time.
56
57 Learn more in the [Workflows documentation](!docs!/learn/fundamentals/workflows).
58
59 ## Fixable
60
61 This rule isn't auto-fixable.