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: AGENTS.md
+10-5Lines changed: 10 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@
7
7
### Avoid Type Casting
8
8
9
9
We **never ever** cast types unless it's absolutely necessary. This includes:
10
+
10
11
- Manual generic type parameters (e.g., `<Type>`)
11
12
- Type assertions using `as`
12
13
- Type assertions using `satisfies`
@@ -15,23 +16,26 @@ We **never ever** cast types unless it's absolutely necessary. This includes:
15
16
### Prefer Type Inference
16
17
17
18
Always infer types and go up the logical chain as far as we can control to determine types. The preferred approach is:
19
+
18
20
1.**Schema validation** - Use schema definitions (e.g., Convex schema, Zod, etc.) as the source of truth
19
21
2.**Type inference from concrete sources** - Let TypeScript infer types from function return types, API responses, etc.
20
22
3.**Go up the chain** - Trace types back to their source rather than casting at the point of use
21
23
22
24
### Example
23
25
24
26
❌ **Bad:**
27
+
25
28
```typescript
26
-
const result =api.getData() asMyType;
27
-
const value =getValue<MyType>();
29
+
const result =api.getData() asMyType
30
+
const value =getValue<MyType>()
28
31
```
29
32
30
33
✅ **Good:**
34
+
31
35
```typescript
32
36
// Infer from schema or API definition
33
-
const result =api.getData();// Type inferred from api.getData return type
34
-
const value =getValue();// Type inferred from function implementation
37
+
const result =api.getData() // Type inferred from api.getData return type
38
+
const value =getValue() // Type inferred from function implementation
35
39
```
36
40
37
41
If types need to be fixed, fix them at the source (schema, API definition, function signature) rather than casting at the point of use.
@@ -45,6 +49,7 @@ If types need to be fixed, fix them at the source (schema, API definition, funct
45
49
Only include the properties from `search` (or other sources) that are actually used in the loader function. This ensures proper cache invalidation and prevents unnecessary re-runs when unrelated search params change.
46
50
47
51
❌ **Bad:**
52
+
48
53
```typescript
49
54
loaderDeps: ({ search }) =>search, // Includes everything, even unused params
50
55
loader: async ({ deps }) => {
@@ -54,6 +59,7 @@ loader: async ({ deps }) => {
54
59
```
55
60
56
61
✅ **Good:**
62
+
57
63
```typescript
58
64
loaderDeps: ({ search }) => ({
59
65
page: search.page,
@@ -66,4 +72,3 @@ loader: async ({ deps }) => {
66
72
```
67
73
68
74
This ensures the loader only re-runs when the specific dependencies change, not when unrelated search params (like `expanded`, `viewMode`, etc.) change.
0 commit comments