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
@@ -16,6 +16,8 @@ This is the project appendix for the **2025 pr05 Grant: Incremental Typescript M
16
16
-[Context](#project-context)
17
17
-[Proposed Approach](#proposed-approach)
18
18
-[Project Timeline](#project-timeline)
19
+
-[Summary of Outcome](#outcome)
20
+
-[Key Decisions](#key-decisions)
19
21
-[Summary of TS Configurations](#configuration-summary)
20
22
-[Migration Tutorial](#migration-tutorial)
21
23
-[Index of Migration Examples](#examples-index)
@@ -88,7 +90,9 @@ This is the project appendix for the **2025 pr05 Grant: Incremental Typescript M
88
90
89
91
### Project Timeline:
90
92
91
-
<detailsopen>
93
+
Click to view details by month
94
+
95
+
<details>
92
96
<summary>July:</summary>
93
97
94
98
- Set up TS dependencies & configuration on the `root`
@@ -131,7 +135,7 @@ This is the project appendix for the **2025 pr05 Grant: Incremental Typescript M
131
135
132
136
</details>
133
137
134
-
<detailsopen>
138
+
<details>
135
139
<summary>October:</summary>
136
140
137
141
- Complete migration for `/server/controllers/User`
@@ -149,6 +153,8 @@ This is the project appendix for the **2025 pr05 Grant: Incremental Typescript M
149
153
150
154
## Outcome:
151
155
156
+
Click to view details & relevant files per outcome-item
157
+
152
158
<details>
153
159
<summary>All TS-related configuration for dependencies is completed</summary>
154
160
@@ -210,42 +216,153 @@ This is the project appendix for the **2025 pr05 Grant: Incremental Typescript M
210
216
211
217
## Key Decisions:
212
218
213
-
- Typescript is used for typechecking only, not compiling
219
+
<details>
220
+
<summary>
221
+
Typescript is configured to be used for type checking only, not for transpiling
222
+
</summary>
223
+
224
+
```shell
225
+
npm run tsc --noEmit
226
+
```
214
227
215
-
- Define "source-of-truth" types in the `./server/types` folder
228
+
- The repo is too large to convert entirely to TS in one go, so we need to flexibly support both TS and JS files
229
+
- We have existing legacy runtime build tools (Babel & Webpack) for the existing JS, so this was the easiest way to support both our intended direction and legacy codebase
230
+
- Our configured automated type checking prevents PRs from being merged if they fail, so we're working towards a Typescript system without disrupting current build.
231
+
- Once the repo has been migrated, we can update to full transpilation with `npm run tsc`
232
+
233
+
</details>
216
234
217
-
- Pull any types that are relevant to share with the `./client` into the `./common/types` folder
235
+
<details>
236
+
<summary>
237
+
Prefer `named` exports over `default` exports where possible
238
+
</summary>
218
239
219
-
- Prefer `named` exports over `default` exports
240
+
❌ DON'T:
220
241
221
-
- JSDocs for API endpoints & client components that hit API endpoints
- If using code-assistance, make sure to write unit tests that cover all happy/unhappy paths to secure against regression. Please see [testing](../testing.md) for more details on general guidelines, or the example code index below.
262
+
// main.ts
263
+
import { multiply } from'./calculator';
264
+
265
+
console.log(multiply(2, 2));
266
+
```
267
+
268
+
- Default exports allow devs to rename the import anything they want, and inaccurate misnaming will cause confusion
269
+
- Renaming default export also makes it more difficult to perform a global search on the function
270
+
271
+
</details>
272
+
273
+
<details>
274
+
<summary>
275
+
Prefer `interface` over `type`
276
+
</summary>
277
+
278
+
- This is not strictly enforced in linting rules, but aims to align with [Google Typescript styling](https://google.github.io/styleguide/tsguide.html#prefer-interfaces). Please see attached link for details.
279
+
280
+
</details>
281
+
282
+
<details>
283
+
<summary>
284
+
If possible, add unit tests prior to the component that you are migrating prior to performing any migration
285
+
</summary>
286
+
287
+
- This protects the app from unintended regression & also helps demonstrate to reviewers that you understand the intent of a component/file you are migrating
288
+
- Tests also help document how the component is intended to work.
289
+
- Please see [testing](../testing.md) for more details on general guidelines, or the example code index below.
290
+
291
+
</details>
292
+
293
+
<details>
294
+
<summary>
295
+
If a component does not have an existing unit test, keep refactors/logic changes outside of Typescript Migration PRs
296
+
</summary
297
+
298
+
- This helps keep reviews easy for maintainers
299
+
- Branch off the migration PR and make a subsequent PR with your proposed refactor.
300
+
301
+
</details>
302
+
303
+
<details>
304
+
<summary>
305
+
Add JSDocs & specify the `Express` `RequestHandler` generics to `/server` controller methods in the following example:
306
+
</summary>
307
+
308
+
```ts
309
+
// see server/controllers/user.controller/userPreferences.ts
310
+
311
+
/**
312
+
* - Method: `PUT`
313
+
* - Endpoint: `/preferences`
314
+
* - Authenticated: `true`
315
+
* - Id: `UserController.updatePreferences`
316
+
*
317
+
* Description:
318
+
* - Update user preferences, such as AppTheme
319
+
*/
320
+
exportconst updatePreferences:RequestHandler<
321
+
{}, // request params type if there are any, extending RouteParam
322
+
UpdatePreferencesResponseBody, // response body type
323
+
UpdatePreferencesRequestBody// request body type
324
+
// query params type if there are any
325
+
> =async (req, res) => {
326
+
// ... rest of code
327
+
};
328
+
```
329
+
330
+
- JSDocs will reduce cognitive load for other developers and enable them to see the controllers details on hover.
331
+
- Add the JSDocs to any `client` controllers that use these endpoints.
332
+
333
+
<imgsrc='./images/hoverJsDocs.gif'alt='hover on a function with jsdocs'width="400px"/>
334
+
335
+
</details>
336
+
337
+
<details>
338
+
<summary>
339
+
Best-effort & evolving-precision principle towards defining types
340
+
</summary>
234
341
235
342
- Make a best effort at being as precise as possible with context clues, but when in doubt, selecting a broader type (eg. `string` instead of an `enum`) is valid and we can update to be stricter as the migration continues.
236
343
237
-
- Keep refactoring/logic updates outside of migration PRs, unless the relevant file has been secured with a test prior to migration work.
238
-
- This helps keep reviews easy for maintainers
239
-
- Branch off the migration PR and make a subsequent PR with your proposed refactor.
344
+
</details>
345
+
346
+
<details>
347
+
<summary>
348
+
`/server` types live in `/server/types`. `/client` types are co-located (currently). Shared types between the `/server` and `/client` live in `/common/types`.
349
+
</summary>
350
+
351
+
-`/server` types are in `/types` folder
352
+
- These types should serves the source-of-truth for the rest of the app.
353
+
- Pull any types that are relevant to share with the `./client` into the `./common/types` folder
354
+
-`/client` types are co-located for now
355
+
- Components have their own types so they will get very numerous and messy
356
+
- However this is open to proposals for change
357
+
358
+
</details>
240
359
241
360
## Configuration Summary:
242
361
243
362
## Migration Tutorial:
244
363
245
364
[Video Guide - Migrating the `client/modules/User/pages/AccountView`](youtube.com/watch?v=y84SVy7lAgg&feature=youtu.be)
0 commit comments