There are a few options for transforming ActiveRecord objects into TypeScript types for a non-monolithic repository:
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.
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.
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.
Asked: 2022-11-26 11:00:00 +0000
Seen: 9 times
Last updated: Sep 25 '22