The `quicktype-typescript-input` package serves as an input module for the `quicktype` code generation tool, specifically enabling the use of TypeScript source code as a schema definition. `quicktype` itself is a robust utility that generates strongly-typed models and serializers from various inputs like JSON, JSON Schema, TypeScript, and GraphQL queries. This package allows developers to define their data structures using TypeScript interfaces or types, and then generate client libraries or data models in numerous target programming languages, including C#, Go, Rust, Java, Swift, Python, and even TypeScript itself with runtime validation. Currently, the package is at version `23.2.6`, aligning with the main `quicktype` project's stable releases. Its primary differentiator is simplifying the process of creating type-safe data access layers by automating boilerplate code, allowing developers to focus on application logic rather than manual data model definition and deserialization.
npm install quicktype-typescript-inputVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically use `quicktype-typescript-input` to take a TypeScript source string defining interfaces and enums, and then generate corresponding type definitions in different target languages like TypeScript or C# using the `quicktype-core` library.
Specify the top-level type name explicitly using the `--top-level NAME` CLI option or the `typeName` option in programmatic usage to ensure consistent naming. Review generated code for unexpected renamings.
Clear browser cache and local storage for `app.quicktype.io` or specifically clear the `localStorage` entry for `quicktype` preferences. This forces the application to re-initialize with correct lowercase language IDs.
Carefully review the JSON Schema. If `additionalProperties: false` is necessary, ensure that all expected properties, including those from `allOf` subschemas, are explicitly defined or allowed at the root or within the merged schema. Consider removing `additionalProperties: false` if strictness is not paramount or if it conflicts with schema composition.
Be aware of potential instabilities or breaking changes. For mission-critical applications, consider converting TypeScript definitions to JSON Schema first, or thoroughly test the generated code for correctness and maintainability. Monitor quicktype's official documentation for updates on this feature's status.
Ensure your `tsconfig.json`'s `include` or `files` array correctly points to your TypeScript source files, or create at least one `.ts` file matched by the configuration.
Adjust the input TypeScript source or JSON Schema to accurately reflect all expected properties, including optionality. Alternatively, modify the consuming code to provide all required properties or handle optional properties correctly (e.g., with null checks).
Clear browser data, specifically local storage, for the `quicktype.io` domain. This will reset language preferences to their default, correctly capitalized values.