Registry / devops / typeconv

typeconv

JSON →
library2.3.1jsnpmunverified

typeconv is a fast, bidirectional type conversion utility that converts between JSON Schema, TypeScript, GraphQL, Open API, and SureType. Version 2.3.1 is the latest stable release. It uses the core-types ecosystem to preserve comments, descriptions, and source locations across conversions. Unlike ad-hoc converters, typeconv provides a unified API and CLI for all supported formats, with high performance and CLI glob support. It is a pure ESM package (no CommonJS) and requires Node.js >= 14.13.1.

npm install typeconv
INSTALL
IMPORT
SIG · TYPECONV
T
typeconv
devopsjavascriptv2.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

typeconv
import { typeconv } from 'typeconv'
const typeconv = require('typeconv')
The package is ESM-only since v2. Named export.
converter
import { converter } from 'typeconv'
Alias for 'typeconv' export.
ConversionOptions
import type { ConversionOptions } from 'typeconv'
const { ConversionOptions } = require('typeconv')
TypeScript type, not a value. Only available as type import.

Shows how to use the API to convert JSON Schema to TypeScript.

import { typeconv } from 'typeconv'; const input = { jsonSchema: { definitions: { User: { type: 'object', title: 'User type', properties: { name: { type: 'string' } }, required: ['name'], }, }, }, }; const result = await typeconv({ from: 'json-schema', to: 'typescript', data: input }); console.log(result.data); // Outputs TypeScript interface definitions
Debug
Known issues
breakingv2 dropped CommonJS support; package is ESM-only
fix
Use ESM imports (import) or migrate to Node >= 14.13.1. CLI usage unaffected.
affects: >=2.0.0
deprecatedv1 had a different API (e.g., typeconv function signature changed)
fix
Update to v2 API: call typeconv with options object instead of positional arguments.
affects: >=1.0.0 <2.0.0
gotchaGlob patterns must be quoted in CLI to avoid shell expansion
fix
Use quotes: typeconv -f ts -t gql -o output 'src/**/*.ts'
affects: all
gotchaConversion preserves comments/descriptions but some types may be lost due to incompatibility between type systems
fix
Check resulting types; JSON Schema constraints (e.g., minLength) are not representable in GraphQL.
affects: all
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using require() on an ESM-only package
fix
Switch to import statement (import { typeconv } from 'typeconv') or use dynamic import().
TypeError: typeconv is not a function
Wrong import or using old API
fix
Ensure correct import: import { typeconv } from 'typeconv'. v2 API is typeconv({ from, to, data }).
ENOENT: no such file or directory, glob pattern mismatch
Shell expanded the glob before passing to typeconv
fix
Quote the glob pattern in CLI: typeconv -f ts -t gql -o output 'types/**/*.ts'
Error: No converter found for 'yaml'
Unsupported type format
fix
Use one of the supported types: json-schema, typescript, graphql, open-api, suretype.
Upgrade
Version history
2.3.1latest on npm
Audit
Dependencies
core-typesrequiredCore library for generic type handling and conversion infrastructure
core-types-json-schemarequiredConverter for JSON Schema types
core-types-tsrequiredConverter for TypeScript types
core-types-graphqlrequiredConverter for GraphQL types
core-types-suretypeoptionalConverter for SureType validators
Agent activity
6 hits · last 30 days
node
6
Resources
typeconv — npm install typeconv · libregistry