Commit 197bc94
Fix recursive type dependency collection issue (#195)
## Summary
- The `DeclCollector` in `generate_ts_definition` only called
`visit_dependencies` on `UserRunConfig`, which per the `ts_rs` API only
visits **direct** type dependencies. Any type referenced indirectly
through a chain of dependencies (e.g. a type nested inside a flattened
struct) would appear in the generated TypeScript output but never be
declared as its own type.
- Fix the collector to recursively call `T::visit_dependencies(self)`
for each visited type, using a `HashSet<TypeId>` to prevent infinite
loops from circular references.
- Add an auto-generated header comment to `run-config.ts` to make it
clear the file should not be edited manually.
### Why this matters
The bug is latent today because all indirect types happen to be
`#[serde(flatten)]`-ed, which causes `ts_rs` to inline their fields
rather than emit separate type declarations. But as soon as a
non-flattened custom type is added at depth > 1 (e.g. a struct
referenced by `EnabledCacheConfig`), the generated TypeScript would
reference that type by name without ever declaring it — producing
invalid TypeScript. The recursive fix future-proofs the collector so any
new nested types are automatically included. The new
`UserGlobalCacheConfig` type (added on `main`) is now correctly emitted
thanks to this fix.
## Test plan
- [x] `cargo test -p vite_task_graph` — all 14 tests pass
- [x] `cargo check` — full project compiles cleanly
- [x] Generated `run-config.ts` includes header and all types
https://claude.ai/code/session_01VQvSgXNnYL8tNWydvtbCvg
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 31fd15f commit 197bc94
2 files changed
+23
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
208 | 210 | | |
209 | 211 | | |
210 | 212 | | |
211 | 213 | | |
212 | 214 | | |
213 | 215 | | |
214 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
215 | 220 | | |
216 | 221 | | |
217 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
218 | 226 | | |
219 | 227 | | |
220 | 228 | | |
221 | | - | |
| 229 | + | |
222 | 230 | | |
| 231 | + | |
| 232 | + | |
223 | 233 | | |
224 | 234 | | |
225 | 235 | | |
226 | | - | |
| 236 | + | |
227 | 237 | | |
228 | 238 | | |
229 | 239 | | |
230 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
231 | 245 | | |
232 | 246 | | |
233 | | - | |
234 | | - | |
| 247 | + | |
| 248 | + | |
235 | 249 | | |
236 | 250 | | |
237 | 251 | | |
238 | 252 | | |
| 253 | + | |
239 | 254 | | |
240 | 255 | | |
241 | 256 | | |
| |||
0 commit comments