{"id":11620,"library":"quicktype-typescript-input","title":"Quicktype TypeScript Input","description":"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.","status":"active","version":"23.2.6","language":"javascript","source_language":"en","source_url":"https://github.com/quicktype/quicktype","tags":["javascript","typescript"],"install":[{"cmd":"npm install quicktype-typescript-input","lang":"bash","label":"npm"},{"cmd":"yarn add quicktype-typescript-input","lang":"bash","label":"yarn"},{"cmd":"pnpm add quicktype-typescript-input","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the core quicktype function and InputData class for programmatic use.","package":"quicktype-core","optional":false},{"reason":"Required for parsing TypeScript input definitions.","package":"typescript","optional":false}],"imports":[{"note":"The core quicktype function and InputData are part of 'quicktype-core', not directly 'quicktype-typescript-input'.","wrong":"import quicktype from 'quicktype';","symbol":"quicktype","correct":"import { quicktype, InputData } from 'quicktype-core';"},{"note":"This package exports the specific input class for TypeScript source.","wrong":"import { TypeScriptInput } from 'quicktype-core';","symbol":"TypeScriptInput","correct":"import { TypeScriptInput } from 'quicktype-typescript-input';"},{"note":"For type-checking quicktype configuration options.","symbol":"QuicktypeOptions","correct":"import { QuicktypeOptions } from 'quicktype-core';"}],"quickstart":{"code":"import { quicktype, InputData } from 'quicktype-core';\nimport { TypeScriptInput } from 'quicktype-typescript-input';\n\nasync function generateTypesFromTypeScript(typescriptSource: string, targetLanguage: string, typeName: string): Promise<string> {\n  const tsInput = new TypeScriptInput();\n  await tsInput.addSource({\n    name: typeName,\n    samples: new Set([typescriptSource])\n  });\n\n  const inputData = new InputData();\n  inputData.addInput(tsInput);\n\n  const { lines } = await quicktype({\n    inputData,\n    lang: targetLanguage,\n    typeName,\n    rendererOptions: {\n      'just-types': 'true' // Common option to only generate types, no serialization code\n    }\n  });\n\n  return lines.join('\\n');\n}\n\nconst myTypeScriptSource = `\ninterface User {\n  id: string;\n  name: string;\n  email: string;\n  isActive: boolean;\n  createdAt: Date;\n}\n\nenum UserRole {\n  Admin = 'admin',\n  Editor = 'editor',\n  Viewer = 'viewer',\n}\n`;\n\n// Example 1: Generate TypeScript interfaces from TypeScript source\ngenerateTypesFromTypeScript(myTypeScriptSource, 'typescript', 'UserAndRole')\n  .then(output => {\n    console.log('Generated TypeScript:\\n', output);\n  })\n  .catch(error => console.error('Error generating TypeScript:', error));\n\n// Example 2: Generate C# classes from TypeScript source\ngenerateTypesFromTypeScript(myTypeScriptSource, 'csharp', 'UserAndRole')\n  .then(output => {\n    console.log('\\nGenerated C#:\\n', output);\n  })\n  .catch(error => console.error('Error generating C#:', error));\n","lang":"typescript","description":"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."},"warnings":[{"fix":"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.","message":"When using `quicktype` programmatically or via CLI, type names might sometimes be unpredictably renamed, especially when inferring types from complex schemas or multiple samples. This can lead to inconsistent generated code and requires manual inspection or explicit `--top-level` naming.","severity":"gotcha","affected_versions":">=20.0.0"},{"fix":"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.","message":"Older versions of the `quicktype` web interface or cached preferences might store language IDs with capitalization (e.g., 'TypeScript'). Newer versions of `quicktype` expect lowercase language IDs (e.g., 'typescript'), which can cause the application to fail loading due to an 'Unknown language name' error.","severity":"breaking","affected_versions":">=23.0.0"},{"fix":"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.","message":"Using `additionalProperties: false` at the root of a JSON Schema in conjunction with `allOf` can lead to unexpected type generation results, as `quicktype` (and JSON Schema validators in general) process these keywords in a way that might not align with intuitive merging behavior.","severity":"gotcha","affected_versions":">=20.0.0"},{"fix":"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.","message":"Generating code from TypeScript input via `quicktype` is still considered 'Experimental' according to the main quicktype GitHub README. This implies that the feature might undergo significant changes, could have limitations, or may not be as stable as JSON or JSON Schema inputs.","severity":"deprecated","affected_versions":">=20.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"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.","cause":"This is a general TypeScript error, often seen when `tsconfig.json`'s `include` or `files` array doesn't match any actual TypeScript files in the project, which can occur during initial setup with `quicktype-typescript-input`.","error":"Error: No inputs were found in config file 'tsconfig.json'"},{"fix":"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).","cause":"Generated TypeScript types are strict by default. This error indicates that an object or value does not conform to the expected interface or type, commonly due to discrepancies between the input data/schema used for generation and the actual data being processed.","error":"Property 'X' is missing in type 'Y' but required in type 'Z'."},{"fix":"Clear browser data, specifically local storage, for the `quicktype.io` domain. This will reset language preferences to their default, correctly capitalized values.","cause":"This error occurs in the quicktype web application or similar environments when a stored preference for a target language uses an outdated or incorrect capitalization (e.g., 'TypeScript' instead of 'typescript').","error":"Uncaught (in promise) Error: Unknown language name: TypeScript"}],"ecosystem":"npm"}