Skip to content

feat: add support for cross-package generic types#105

Merged
franklinkim merged 4 commits into
feature/genericsfrom
feature/generics-cross-package-support
May 26, 2026
Merged

feat: add support for cross-package generic types#105
franklinkim merged 4 commits into
feature/genericsfrom
feature/generics-cross-package-support

Conversation

@danielthomas74

@danielthomas74 danielthomas74 commented May 22, 2026

Copy link
Copy Markdown

Description

Add cross-package generic type support to the code generator. Generic types referenced across package boundaries (e.g. private.Envelope[server.Item]) now carry their type arguments through parsing, resolution, and into both Go and TypeScript code generation.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactoring
  • ⚡ Performance
  • ✅ Tests
  • 🔧 Build/CI

Changes

  • model.Value gains TypeArgs []*Value slot; canonical home for generic instantiations regardless of underlying Scalar/StructType kind.
  • internal/parser/typereader.go: IndexExpr / IndexListExpr push directly to v.TypeArgs after recursing into the generic base type. Handles both cross-package selector idents (parsed as Scalar) and same-package idents (parsed as StructType).
  • internal/parser/servicereader.go: loadFlatStructsValue, needsWorkValue, getStructTypesForField, getScalarForField walk value.TypeArgs uniformly so dependency resolution and import collection reach into generic arguments.
  • internal/codegen/gocode.go: new renderGoTypeArgs helper; both Scalar and StructType render paths emit [A, B]. extractImportValue walks TypeArgs so cross-package args are imported.
  • internal/codegen/typescript.go: renderTSTypeArgs called from Scalar and StructType branches so cross-package generics render <A, B> correctly.
  • tests/generics/: new test fixture covering same-package + cross-package generics, pointer-to-generic, nested generics, generics of foreign types. Bun-based TS client tests roundtrip through a real server.

Checklist

  • My code adheres to the coding and style guidelines of the project.
  • I have performed a self-review of my own code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.

@franklinkim franklinkim marked this pull request as ready for review May 26, 2026 13:08
@franklinkim franklinkim merged commit fbe91b7 into feature/generics May 26, 2026
1 check passed
@franklinkim franklinkim deleted the feature/generics-cross-package-support branch May 26, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants