Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript types for Golang structs #8545

Open
turadg opened this issue Nov 17, 2023 · 2 comments
Open

TypeScript types for Golang structs #8545

turadg opened this issue Nov 17, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@turadg
Copy link
Member

turadg commented Nov 17, 2023

What is the Problem Being Solved?

Golang defines structure that the JS bridge receives, but they aren't typed on the JS side.

E.g. https://github.com/Agoric/agoric-sdk/blob/0af17b23935ff210d0e4f69e8f7d2f4079d09689/golang/cosmos/x/swingset/keeper/proposal.go#L9-L27

The lack of a type leads to re-implementing them: https://github.com/Agoric/agoric-sdk/blob/master/packages/vats/src/core/chain-behaviors.js#L60-L68

In that case it's a one-off. #8544 defines them more centrally, but still manually by adapting the Golang source.

Description of the Design

Generate the types automatically from the Golang source.

Perhaps using https://github.com/gzuidhof/tygo

An alternative,

typescriptify-golang-structs: Probably the most popular choice. The downside of this package is that it relies on reflection rather than parsing, which means that certain things can't be kept such as comments without adding a bunch of tags to your structs. The CLI generates a Go file which is then executed and reflected on, and its library requires you to manually specify all types that should be converted.

Security Considerations

n/a

Scaling Considerations

n/a

Test Plan

Needs to work in CI and dev workflow

Upgrade Considerations

n/a

@turadg turadg added the enhancement New feature or request label Nov 17, 2023
@dckc
Copy link
Member

dckc commented Nov 17, 2023

I wonder about endo patterns too.

Reusing mature go->ts tools seems more feasible than building go->patterns tooling. But if we can build patterns one way or another and then generate types from such patterns (#6160), we should be able to test that the types generated from go and the types generated from patterns match reasonably well.

@JimLarson
Copy link
Contributor

Note that we're planning to replace our ad-hoc bridge protocol with JSON-RPC, which might help the situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants