The Contentstack CLI TSGen plugin generates TypeScript typings from REST API and GraphQL queries. The type file containing the TypeScript typings assists developers in working with content types, global fields, and GraphQL queries in TypeScript.
With the TSGen plugin, you can annotate interfaces and fields with comments from the JSDoc library. Additionally, the TSGen plugin allows you to add prefixes to interfaces.
Note: The Contentstack CLI uses the introspection query to generate a GraphQL schema.
This step-by-step guide lets you install and use the tsgen plugin in the CLI.
csdx plugins:install contentstack-cli-tsgencsdx auth:tokens:add --deliveryNote: Skip this step if you already have a delivery token as an alias.
csdx tsgen
csdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts"csdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" --branch "develop"csdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" -p "I"csdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" --no-doccsdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" --api-type graphqlcsdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" --api-type graphql --namespace "GraphQL"csdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" --include-editable-tagscsdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" --include-referenced-entrycsdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" --include-system-fields --include-referenced-entryNote: Together, these two flags enable full, accurate Entry typings, ensuring that relationships, system metadata, and dynamic references are all represented correctly in the generated TypeScript definitions.
Additional Resource: For a major TSGen version upgrade, refer to the Migration.md file in the GitHub repository.