Home

Awesome

npm version downloads build status coverage status Node.JS version

core-types-ts

This package provides conversion functions between core-types and TypeScript.

You probably don't want to use this package directly, but rather typeconv which uses this package to convert between TypeScript, JSON Schema and GraphQL.

See

Other conversion packages:

Versions

Since 4.0, this package is pure ESM and requires Node 14.13.1 or later.

Contents

Usage

There are two conversion functions, convertCoreTypesToTypeScript and convertTypeScriptToCoreTypes, both returning a wrapped value, of the type ConversionResult.

core-types to TypeScript

import { convertCoreTypesToTypeScript } from 'core-types-ts'

let doc; // This core-types document comes from somewhere

const { data: tsSourceCode } = convertCoreTypesToTypeScript( doc );

You can provide options as a second argument fn the type:

interface ToTsOptions
{
	warn?: WarnFunction;
	filename?: string;
	sourceFilename?: string;
	useUnknown?: boolean;
	declaration?: boolean;
	userPackage?: string;
	userPackageUrl?: string;
	noDisableLintHeader?: boolean;
	noDescriptiveHeader?: boolean;
	namespaces?: 'ignore'| 'dot'| 'underscore'| 'all';
	unsupported?: 'ignore' | 'warn' | 'error';
}

These options are all optional.

The warn function is of type WarnFunction from core-types, meaning it takes a message as string, and an optional second argument of type CoreTypesErrorMeta, also from core-types.

TypeScript to core-types

import { convertTypeScriptToCoreTypes } from 'core-types-ts'

let sourceCode; // This source code comes from somewhere

const { data: doc } = convertTypeScriptToCoreTypes( sourceCode );

An optional second argument can be provided on the form

interface FromTsOptions
{
	warn?: WarnFunction;
	namespaces?: 'ignore' | 'hoist' | 'join-dot' | 'join-underscore';
	nonExported?: 'fail' | 'ignore' | 'include' | 'inline' | 'include-if-referenced';
	unsupported?: 'ignore' | 'warn' | 'error';
}