Ask Your Question
1

How can ActiveRecord objects be transformed into TypeScript types for a non-monolithic repository?

asked 2022-11-26 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-09-25 14:00:00 +0000

pufferfish gravatar image

There are a few options for transforming ActiveRecord objects into TypeScript types for a non-monolithic repository:

  1. Use a tool to generate TypeScript types from ActiveRecord models. There are a few tools available that can inspect ActiveRecord models and generate TypeScript types based on their fields and associations. Examples of such tools include ts-activerecord and rails-to-typescript.

  2. Define TypeScript interfaces manually based on the ActiveRecord models. In this approach, you would create a TypeScript interface for each ActiveRecord model, defining its fields and associations in TypeScript syntax. This can be done manually or with the help of a code generation tool.

  3. Use GraphQL to abstract away the ActiveRecord models and define TypeScript types based on API responses. With this approach, you would define a GraphQL schema that encapsulates the ActiveRecord models and exposes them as a GraphQL API. With GraphQL, you can define the types of the API responses in TypeScript syntax, which can be used to generate TypeScript code that interacts with the API.

Overall, the best approach will depend on the specific needs and constraints of your project.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-11-26 11:00:00 +0000

Seen: 9 times

Last updated: Sep 25 '22