Registry / devops / core-types

core-types

JSON →
library3.1.0jsnpmunverified

Generic type declarations and utilities for converting between TypeScript, GraphQL, JSON Schema and other type systems. Current stable version: 3.1.0. Pure ESM package requiring Node >=14.13.1 || >=16.0.0. Used by packages like core-types-json-schema, core-types-ts, core-types-graphql, core-types-suretype, and typeconv. Key differentiator: provides a minimal, well-defined set of types (any, null, boolean, string, number, object, array, tuple, ref, union, intersection) as an interchange format, with simplification, validation, and traversal functions. Supersedes ad-hoc type conversion by providing a normalized intermediate representation.

npm install core-types
INSTALL
IMPORT
SIG · CORE-TYPES
C
core-types
devopsjavascriptv3.1.0
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.

NodeType
import type { NodeType } from 'core-types'
import { NodeType } from 'core-types'
NodeType is a type-only export; if you use TypeScript, use 'import type' to avoid emitting runtime code.
simplify
import { simplify } from 'core-types'
const { simplify } = require('core-types')
core-types is pure ESM since v3.0; require() will fail. Use dynamic import or ES module syntax.
validate
import { validate } from 'core-types'
import validate from 'core-types'
validate is a named export, not a default export. Also available via import { validate } from 'core-types'.

Demonstrates importing core-types types and functions, creating a type, simplifying unions, validating, traversing, and using some().

import { NodeType, simplify, validate, traverse, some } from 'core-types'; const type: NodeType = { type: 'string' }; console.log('Simple type:', type); // Simplify a union type const unionType: NodeType = { or: [{ type: 'string' }, { type: 'number' }] }; const simplified = simplify(unionType); console.log('Simplified:', JSON.stringify(simplified)); // Validate a type const errors = validate(unionType); if (errors.length > 0) { console.error('Validation errors:', errors); } // Traverse type tree traverse(unionType, (node, path) => { console.log(`Node at ${path.join('.')}:`, node.type); }); // Check if any type matches a predicate const hasString = some(unionType, (node) => node.type === 'string'); console.log('Has string?', hasString);
Debug
Known issues
breakingSince v3.0, core-types is pure ESM and requires Node >=14.13.1 (or >=16.0.0).
fix
Ensure your project uses ES modules (type: 'module' in package.json or .mjs files) and Node version >=14.13.1.
affects: >=3.0.0
deprecatedThe 'some' function is deprecated in favor of 'traverse' with a predicate callback.
fix
Use traverse with a custom predicate instead of some().
affects: >=3.0.0
gotchasimplify() is type-wise lossless but may remove annotations (e.g. descriptions).
fix
Preserve descriptions by applying them after simplification, or check that they are not critical before simplifying.
affects: *
gotchaThe package only provides type definitions and functions; it does not perform actual conversion between type systems. You need companion packages like core-types-json-schema.
fix
Install additional packages (e.g., core-types-json-schema, core-types-ts) for conversion to specific formats.
affects: *
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() to import an ES module. core-types is ESM-only since v3.0.
fix
Change to import syntax (e.g., import { simplify } from 'core-types') and ensure your project uses ES modules.
Cannot find module 'core-types'
Package not installed or incorrect import path.
fix
Run npm install core-types and verify import path is correct (no subpath imports needed).
TypeError: core_types.simplify is not a function
Using default import (import core_types from 'core-types') but simplify is a named export.
fix
Use named import: import { simplify } from 'core-types'.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
core-types — npm install core-types · libregistry