The `microcms-typescript` package is a command-line interface (CLI) tool designed to generate TypeScript type definitions directly from MicroCMS API schema JSON files. Currently stable at version 1.0.15, this utility provides a bridge between your MicroCMS content models and your TypeScript codebase, enabling strong type-safety for your MicroCMS data. Unlike the `microcms-js-sdk` or `microcms-ts-sdk` which are client libraries for interacting with the MicroCMS API, `microcms-typescript` focuses solely on code generation. It processes local JSON files representing MicroCMS API schemas and outputs corresponding TypeScript `type` declarations, including a comprehensive `EndPoints` type that encapsulates `gets`, `get`, `post`, `put`, and `patch` operations, ensuring type-safe access to your content structure. This distinction is crucial as it targets the build-time generation of types rather than runtime API interaction.
npm install microcms-typescriptVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install the `microcms-typescript` CLI, create a sample MicroCMS schema JSON file, run the tool to generate `cms-types.ts`, and then import and use the generated `EndPoints` types in a TypeScript application to ensure type safety for your MicroCMS data.
Regularly check for updates to `microcms-typescript` and review generated types after MicroCMS platform updates. If issues arise, report them to the maintainer or temporarily pin to a working version.
Avoid making manual edits to the generated type file. If custom types are needed, extend the generated types in a separate file, or integrate the generation step into your build process to manage the output consistently.
Ensure your project's Node.js environment and `devDependencies` for `typescript` are sufficiently modern (e.g., Node.js v18+ and TypeScript v5.0+ are recommended for new projects). Update `tsconfig.json` compiler options like `target`, `module`, and `esModuleInterop` to align with modern standards.
Do not import `microcms-typescript` into your code. Instead, run it as a CLI command using `npx microcms-typescript` or, if installed globally, `microcms-typescript`.
Verify that the `src-dir` argument points to an existing directory containing your MicroCMS schema JSON files. Ensure correct casing and full path if running from a different working directory.
Inspect the specified JSON file (`<path/to/schema.json>`) for syntax errors. Validate its content against the expected MicroCMS API schema structure.
First, ensure your MicroCMS schema JSON files are up-to-date and reflect your current API structure. Then, re-run the `microcms-typescript` CLI to regenerate `cms-types.ts`. Double-check the API name used (e.g., 'blogs') matches the filename of your schema JSON (e.g., `api-blogs-schema.json`).
No dependency data recorded yet.