npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@typedly/schema

v2.0.1

Published

A TypeScript type definitions package for schema modeling.

Readme

@typedly/schema

npm version GitHub issues GitHub license

GitHub issues GitHub forks GitHub stars GitHub license

GitHub Sponsors Patreon Sponsors

A TypeScript type definitions package for schema modeling.

Features

  • Type-level schema-to-TypeScript conversion (SchemaToType)
  • Optional key support via ? marker (e.g. email?)
  • Primitive schema mapping (string, number, boolean, date)
  • Array schema support for primitives and nested object items
  • Zero runtime cost (types only)

Table of contents

Installation

npm install @typedly/schema --save-peer

Api

import {
  SchemaRecordToType,
  SchemaToType,
  SchemaTypeMap,
  SchemaValue,
} from '@typedly/schema';

Type

SchemaRecordToType

import { SchemaRecordToType } from '@typedly/schema';

type dbSchema = SchemaRecordToType<{
  person: { id: 'number', name: 'string' },
  cart: { id: 'number', items: { array: 'string' } },
}>;

// Result:
// type dbSchema = {
//   person: {
//     id: number;
//     name: string;
//   };
//   cart: {
//     id: number;
//     items: string[];
//   };
// }

SchemaToType

import type { SchemaToType } from '@typedly/schema';

// Oops, an end user writes this:
const OopsSchema = {
  tags: ["a", "b"] // native string[]! Not the schema style, but tolerated
}
type Result = SchemaToType<typeof OopsSchema>
// tags: string[]   (instead of never)

SchemaTypeMap

import { SchemaTypeMap } from '@typedly/schema';

SchemaValue

import { SchemaValue } from '@typedly/schema';

// 1a. Primitive array:
type Ex1 = SchemaValue<{ array: 'string' }>;
// => string[]

// 1b. Nested object array:
type Ex2 = SchemaValue<{ array: { id: 'number', name: 'string' } }>;
// => { id: number; name: string; }[]

// 1c. Deeply nested arrays:
type Ex3 = SchemaValue<{ array: { array: 'boolean' } }>;
// => boolean[][]

// 2. Primitive type:
type Ex4 = SchemaValue<'string'>; // string
// => string

type Ex5 = SchemaValue<'number'>; // number
// => number

type Ex6 = SchemaValue<'boolean'>; // boolean
// => boolean

type Ex7 = SchemaValue<'date'>;    // Date
// => Date

// 4. readonly any[] — Native TypeScript array (forgiveness fallback)
type Ex8 = SchemaValue<string[]>; // string[]

// 5. Record<string, any> — Nested object (schema for object)
type Ex9 = SchemaValue<{ id: 'number'; name: 'string' }>;
// => { id: number; name: string; }

// 6. Invalid types (not in SchemaTypeMap, not an array, not a nested object)
type Ex13 = SchemaValue<null>;      // never
type Ex14 = SchemaValue<undefined>; // never
type Ex15 = SchemaValue<()=>void>;  // never
type Ex16 = SchemaValue<42>;        // never

Examples

Providing

import type { SchemaToType } from '@typedly/schema';

function createSchema<const Schema extends Record<string, unknown>>(schema: Schema) {
  return (user: SchemaToType<Schema>) => user;
}

// 
const userSchema = createSchema({
  id: "number",
  name: "string",
  active: "boolean",
  createdAt: "date",
})({
  id: 1,
  name: "John",
  active: true,
  createdAt: new Date(),
});

1) Basic schema to type

import type { SchemaToType } from '@typedly/schema';

type UserSchema = {
  id: 'number';
  name: 'string';
  active: 'boolean';
  createdAt: 'date';
};

type User = SchemaToType<UserSchema>;
// {
//   id: number;
//   name: string;
//   active: boolean;
//   createdAt: Date;
// }

2) Optional keys with ?

import type { SchemaToType } from '@typedly/schema';

type UserSchema = {
  id: 'number';
  name: 'string';
  email?: 'string';
};

type User = SchemaToType<UserSchema>;
// {
//   id: number;
//   name: string;
//   email?: string;
// }

3) Arrays of primitives

import type { SchemaToType } from '@typedly/schema';

type PostSchema = {
  id: 'number';
  tags: { array: 'string' };
  ratings: { array: 'number' };
};

type Post = SchemaToType<PostSchema>;
// {
//   id: number;
//   tags: string[];
//   ratings: number[];
// }

4) Arrays of objects

import type { SchemaToType } from '@typedly/schema';

type UserSchema = {
  id: 'number';
  test: { array: { id: 'number'; label: 'string' } };
};

type User = SchemaToType<UserSchema>;
// {
//   id: number;
//   test: { id: number; label: string }[];
// }

5) Nested object schema

import type { SchemaToType } from '@typedly/schema';

type AccountSchema = {
  id: 'number';
  profile: {
    firstName: 'string';
    lastName: 'string';
    'phone?': 'string';
  };
};

type Account = SchemaToType<AccountSchema>;
// {
//   id: number;
//   profile: {
//     firstName: string;
//     lastName: string;
//     phone?: string;
//   };
// }

Contributing

Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.

Support

If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.

Support via:

or via Trust Wallet

Thanks for your support!

Code of Conduct

By participating in this project, you agree to follow Code of Conduct.

GIT

Commit

Versioning

Semantic Versioning 2.0.0

Given a version number MAJOR.MINOR.PATCH, increment the:

  • MAJOR version when you make incompatible API changes,
  • MINOR version when you add functionality in a backwards-compatible manner, and
  • PATCH version when you make backwards-compatible bug fixes.

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

FAQ How should I deal with revisions in the 0.y.z initial development phase?

The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.

How do I know when to release 1.0.0?

If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.

License

MIT © typedly (license)

Packages

  • @typedly/array: A TypeScript type definitions package to handle array-related operations.
  • @typedly/callback: A TypeScript type definitions package for asynchronous and synchronous callback functions of various types.
  • @typedly/character: A TypeScript type definitions package for various character types.
  • @typedly/context: A TypeScript type definitions package for context data structures.
  • @typedly/descriptor: A TypeScript type definitions package for property descriptor.
  • @typedly/digit: A TypeScript type definitions package for digit types.
  • @typedly/letter: A TypeScript type definitions package for handling letter types.
  • @typedly/object: A TypeScript type definitions package to handle object-related operations.
  • @typedly/payload: A TypeScript type definitions package for payload data structures.
  • @typedly/property: A TypeScript type definitions package to handle object property-related operations.
  • @typedly/regexp: A TypeScript type definitions package for RegExp.
  • @typedly/symbol: A TypeScript type definitions package for various symbols.