You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/web/src/app/(docs)/docs/conventions/page.mdx
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,47 @@ const bar = () => {
64
64
};
65
65
```
66
66
67
+
## Arrow functions
68
+
69
+
Use arrow functions instead of the `function` keyword.
70
+
71
+
```ts
72
+
// Prefer
73
+
exportconst createUser = (data:UserData):User=> {
74
+
// implementation
75
+
};
76
+
77
+
// Avoid
78
+
exportfunction createUser(data:UserData):User {
79
+
// implementation
80
+
}
81
+
```
82
+
83
+
Why arrow functions?
84
+
85
+
-**No hoisting** - Combined with `const`, arrow functions aren't hoisted, which enforces top-down code organization
86
+
-**Consistency** - One way to define functions means less cognitive overhead
87
+
-**Currying** - Arrow functions make currying natural for [dependency injection](/docs/dependency-injection)
88
+
89
+
**Exception: function overloads.** TypeScript requires the `function` keyword for overloaded signatures:
90
+
91
+
```ts
92
+
exportfunction mapArray<T, U>(
93
+
array:NonEmptyReadonlyArray<T>,
94
+
mapper: (item:T) =>U,
95
+
):NonEmptyReadonlyArray<U>;
96
+
exportfunction mapArray<T, U>(
97
+
array:ReadonlyArray<T>,
98
+
mapper: (item:T) =>U,
99
+
):ReadonlyArray<U>;
100
+
exportfunction mapArray<T, U>(
101
+
array:ReadonlyArray<T>,
102
+
mapper: (item:T) =>U,
103
+
):ReadonlyArray<U> {
104
+
returnarray.map(mapper) asReadonlyArray<U>;
105
+
}
106
+
```
107
+
67
108
## Immutability
68
109
69
110
Mutable state is tricky because it increases the risk of unintended side effects, makes code harder to predict, and complicates debugging—especially in complex applications where data might be shared or modified unexpectedly. Favor immutable values using readonly types to reduce these risks and improve clarity.
0 commit comments