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
When Go types are referenced across different files in the same package, the generated TypeScript code does not properly import these types, causing TypeScript compilation errors.
5
+
6
+
## Test Case: `type_separate_files`
7
+
-`memory.go` defines: `type file struct { name string; data []byte }`
1.`memory.gs.ts` generates the `file` class but doesn't export it (because it's unexported in Go)
13
+
2.`storage.gs.ts` references `file` type but doesn't import it from `memory.gs.ts`
14
+
3. TypeScript compilation fails: `Cannot find name 'file'`
15
+
16
+
## Expected TypeScript Output
17
+
-`memory.gs.ts` should export the `file` class (even though unexported in Go)
18
+
-`storage.gs.ts` should import `{ file }` from `"./memory.gs.ts"`
19
+
20
+
## Analysis Completed
21
+
22
+
### Current Function Import System
23
+
The compiler already has a system for cross-file function imports:
24
+
-`PackageAnalysis.FunctionDefs` tracks which functions are defined in each file
25
+
-`PackageAnalysis.FunctionCalls` tracks which functions each file calls from other files
26
+
-`compiler.go` lines 602-622 generate import statements for functions
27
+
28
+
### Root Cause
29
+
1.**Export Issue**: In `spec-struct.go` line 23, structs are only exported if `a.Name.IsExported()` is true. For unexported types like `file`, this is false.
30
+
2.**Import Issue**: There's no equivalent to `FunctionCalls` for tracking type dependencies across files.
31
+
32
+
### Solution Approach
33
+
1.**Always export types within same package**: Modify struct generation to export all types (even unexported ones) when generating TypeScript for same-package consumption
34
+
2.**Add type dependency tracking**: Add `TypeDefs` and `TypeCalls` to `PackageAnalysis` similar to function tracking
35
+
3.**Generate type imports**: Add import generation for types similar to function imports
36
+
37
+
## Implementation Plan
38
+
1. Add `TypeDefs` and `TypeCalls` fields to `PackageAnalysis` struct
39
+
2. Implement type dependency analysis in `AnalyzePackage` function
40
+
3. Modify struct generation to always export types within same package
0 commit comments